updates lightinject, adds method to create an LI container from an MSDI collection, updates a test
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using Umbraco.Core.Logging;
|
||||
|
||||
namespace Umbraco.Tests.TestHelpers
|
||||
namespace Umbraco.Core.Logging
|
||||
{
|
||||
public class ConsoleLogger : ILogger
|
||||
{
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Umbraco.Core.Logging
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Defines the logging service.
|
||||
/// </summary>
|
||||
|
||||
@@ -21,6 +21,8 @@ namespace Umbraco.Core.Composing.LightInject
|
||||
Container = ConfigureContainer(container);
|
||||
}
|
||||
|
||||
//TODO: The Create methods can die when net framework is gone
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="LightInjectContainer"/> class.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
using System;
|
||||
using LightInject;
|
||||
using LightInject.Microsoft.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using Umbraco.Core.Composing.LightInject;
|
||||
using Umbraco.Core.Configuration;
|
||||
|
||||
namespace Umbraco.Core.Composing
|
||||
@@ -9,7 +13,19 @@ namespace Umbraco.Core.Composing
|
||||
/// </summary>
|
||||
public static class RegisterFactory
|
||||
{
|
||||
//TODO This needs to die
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="IRegister"/> based on an existing MSDI IServiceCollection
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
/// <returns></returns>
|
||||
public static IRegister CreateFrom(IServiceCollection services, out IServiceProvider serviceProvider)
|
||||
{
|
||||
var liContainer = new ServiceContainer(ContainerOptions.Default.WithMicrosoftSettings());
|
||||
serviceProvider = liContainer.CreateServiceProvider(services);
|
||||
return new LightInjectContainer(liContainer);
|
||||
}
|
||||
|
||||
//TODO: The following can die when net framework is gone
|
||||
|
||||
// cannot use typeof().AssemblyQualifiedName on the web container - we don't reference it
|
||||
// a normal Umbraco site should run on the web container, but an app may run on the core one
|
||||
|
||||
@@ -7,10 +7,12 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="HtmlAgilityPack" Version="1.8.14" />
|
||||
<PackageReference Include="LightInject" Version="6.2.0" />
|
||||
<PackageReference Include="LightInject" Version="6.3.2" />
|
||||
<PackageReference Include="LightInject.Annotation" Version="1.1.0" />
|
||||
<PackageReference Include="LightInject.Microsoft.DependencyInjection" Version="3.3.0" />
|
||||
<PackageReference Include="Markdown" Version="2.2.1" />
|
||||
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.2" />
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" />
|
||||
<PackageReference Include="MiniProfiler.Shared" Version="4.1.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
@@ -65,4 +67,8 @@
|
||||
<ProjectReference Include="..\Umbraco.Core\Umbraco.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Composing\Microsoft\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -13,11 +13,44 @@ using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Runtime;
|
||||
using Umbraco.Tests.Integration.Infrastructure;
|
||||
|
||||
namespace Umbraco.Tests.Integration
|
||||
{
|
||||
[TestFixture]
|
||||
public class CrossWireContainer
|
||||
public class RuntimeTests
|
||||
{
|
||||
[Test]
|
||||
public void CoreRuntime()
|
||||
{
|
||||
// MSDI
|
||||
var services = new ServiceCollection();
|
||||
var msdiServiceProvider = services.BuildServiceProvider();
|
||||
|
||||
// LightInject / Umbraco
|
||||
var umbracoContainer = RegisterFactory.CreateFrom(services, out var lightInjectServiceProvider);
|
||||
|
||||
// Dependencies needed for Core Runtime
|
||||
var profiler = new VoidProfiler();
|
||||
var logger = new ProfilingLogger(new ConsoleLogger(new MessageTemplates()), profiler);
|
||||
var hostingEnvironment = new TestHostingEnvironment();
|
||||
var ioHelper = new IOHelper(hostingEnvironment);
|
||||
var configs = new Configs(x => null);
|
||||
var umbracoVersion = new UmbracoVersion();
|
||||
var testUmbracoBootPermissionChecker = new TestUmbracoBootPermissionChecker();
|
||||
var globalSettings = new TestGlobalSettings();
|
||||
var backOfficeInfo = new TestBackOfficeInfo(globalSettings);
|
||||
var dbFactoryProviderCreator = new TestDbProviderFactoryCreator();
|
||||
var mainDom = new SimpleMainDom();
|
||||
var coreRuntime = new CoreRuntime(configs, umbracoVersion, ioHelper, logger, profiler, testUmbracoBootPermissionChecker, hostingEnvironment, backOfficeInfo, dbFactoryProviderCreator, mainDom);
|
||||
|
||||
var factory = coreRuntime.Boot(umbracoContainer);
|
||||
}
|
||||
}
|
||||
|
||||
[TestFixture]
|
||||
public class ContainerTests
|
||||
{
|
||||
[Test]
|
||||
public void CrossWire()
|
||||
@@ -27,26 +60,24 @@ namespace Umbraco.Tests.Integration
|
||||
services.AddSingleton<Foo>();
|
||||
var msdiServiceProvider = services.BuildServiceProvider();
|
||||
|
||||
// LightInject
|
||||
var liContainer = new ServiceContainer(ContainerOptions.Default.WithMicrosoftSettings());
|
||||
var liServiceProvider = liContainer.CreateServiceProvider(services);
|
||||
|
||||
// Umbraco
|
||||
var umbracoContainer = new LightInjectContainer(liContainer);
|
||||
// LightInject / Umbraco
|
||||
var umbracoContainer = (LightInjectContainer)RegisterFactory.CreateFrom(services, out var lightInjectServiceProvider);
|
||||
|
||||
// Dependencies needed for creating composition/register essentials
|
||||
var tempPath = Path.Combine(Path.GetTempPath(), "umbraco-temp-" + Guid.NewGuid());
|
||||
if (!Directory.Exists(tempPath)) Directory.CreateDirectory(tempPath);
|
||||
var globalSettings = Mock.Of<IGlobalSettings>();
|
||||
var typeFinder = Mock.Of<ITypeFinder>();
|
||||
var ioHelper = Mock.Of<IIOHelper>();
|
||||
|
||||
var hostingEnvironment = new TestHostingEnvironment();
|
||||
var ioHelper = new IOHelper(hostingEnvironment);
|
||||
var runtimeCache = NoAppCache.Instance;
|
||||
var logger = Mock.Of<IProfilingLogger>();
|
||||
var profiler = new VoidProfiler();
|
||||
var logger = new ProfilingLogger(new ConsoleLogger(new MessageTemplates()), profiler);
|
||||
var typeFinder = new TypeFinder(logger, new DefaultUmbracoAssemblyProvider(GetType().Assembly));
|
||||
var typeLoader = new TypeLoader(ioHelper, typeFinder, runtimeCache, new DirectoryInfo(tempPath), logger, false);
|
||||
var runtimeState = Mock.Of<IRuntimeState>();
|
||||
var configs = new Configs(x => null);
|
||||
var appCaches = new AppCaches(runtimeCache, NoAppCache.Instance, new IsolatedCaches(type => new ObjectCacheAppCache(typeFinder)));
|
||||
var profiler = new VoidProfiler();
|
||||
var mainDom = Mock.Of<IMainDom>();
|
||||
var umbracoDatabaseFactory = Mock.Of<IUmbracoDatabaseFactory>();
|
||||
var umbracoVersion = new UmbracoVersion();
|
||||
@@ -60,7 +91,7 @@ namespace Umbraco.Tests.Integration
|
||||
|
||||
// From MSDI
|
||||
var foo1 = msdiServiceProvider.GetService<Foo>();
|
||||
var foo2 = liServiceProvider.GetService<Foo>();
|
||||
var foo2 = lightInjectServiceProvider.GetService<Foo>();
|
||||
var foo3 = umbracoContainer.GetInstance<Foo>();
|
||||
|
||||
Assert.IsNotNull(foo1);
|
||||
@@ -0,0 +1,17 @@
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
|
||||
namespace Umbraco.Tests.Integration.Infrastructure
|
||||
{
|
||||
|
||||
public class TestBackOfficeInfo : IBackOfficeInfo
|
||||
{
|
||||
public TestBackOfficeInfo(IGlobalSettings globalSettings)
|
||||
{
|
||||
GetAbsoluteUrl = globalSettings.UmbracoPath;
|
||||
}
|
||||
|
||||
public string GetAbsoluteUrl { get; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using System.Data.Common;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.SqlSyntax;
|
||||
|
||||
namespace Umbraco.Tests.Integration.Infrastructure
|
||||
{
|
||||
public class TestDbProviderFactoryCreator : IDbProviderFactoryCreator
|
||||
{
|
||||
public IBulkSqlInsertProvider CreateBulkSqlInsertProvider(string providerName)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public void CreateDatabase()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public DbProviderFactory CreateFactory()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public DbProviderFactory CreateFactory(string providerName)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public ISqlSyntaxProvider GetSqlSyntaxProvider(string providerName)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
using Umbraco.Core.Configuration;
|
||||
|
||||
namespace Umbraco.Tests.Integration.Infrastructure
|
||||
{
|
||||
public class TestGlobalSettings : IGlobalSettings
|
||||
{
|
||||
public string ReservedUrls => throw new System.NotImplementedException();
|
||||
|
||||
public string ReservedPaths => throw new System.NotImplementedException();
|
||||
|
||||
public string Path => throw new System.NotImplementedException();
|
||||
|
||||
public string ConfigurationStatus { get => throw new System.NotImplementedException(); set => throw new System.NotImplementedException(); }
|
||||
|
||||
public int TimeOutInMinutes => throw new System.NotImplementedException();
|
||||
|
||||
public string DefaultUILanguage => throw new System.NotImplementedException();
|
||||
|
||||
public bool HideTopLevelNodeFromPath => throw new System.NotImplementedException();
|
||||
|
||||
public bool UseHttps => throw new System.NotImplementedException();
|
||||
|
||||
public int VersionCheckPeriod => throw new System.NotImplementedException();
|
||||
|
||||
public string UmbracoPath => "/Umbraco";
|
||||
|
||||
public string UmbracoCssPath => throw new System.NotImplementedException();
|
||||
|
||||
public string UmbracoScriptsPath => throw new System.NotImplementedException();
|
||||
|
||||
public string UmbracoMediaPath => throw new System.NotImplementedException();
|
||||
|
||||
public bool IsSmtpServerConfigured => throw new System.NotImplementedException();
|
||||
|
||||
public ISmtpSettings SmtpSettings => throw new System.NotImplementedException();
|
||||
|
||||
public bool InstallMissingDatabase => throw new System.NotImplementedException();
|
||||
|
||||
public bool InstallEmptyDatabase => throw new System.NotImplementedException();
|
||||
|
||||
public bool DisableElectionForSingleServer => throw new System.NotImplementedException();
|
||||
|
||||
public string RegisterType => throw new System.NotImplementedException();
|
||||
|
||||
public string DatabaseFactoryServerVersion => throw new System.NotImplementedException();
|
||||
|
||||
public string MainDomLock => throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Hosting;
|
||||
|
||||
namespace Umbraco.Tests.Integration.Infrastructure
|
||||
{
|
||||
|
||||
public class TestHostingEnvironment : IHostingEnvironment
|
||||
{
|
||||
public TestHostingEnvironment()
|
||||
{
|
||||
var tempPath = Path.Combine(Path.GetTempPath(), "umbraco-temp-" + Guid.NewGuid());
|
||||
if (!Directory.Exists(tempPath)) Directory.CreateDirectory(tempPath);
|
||||
LocalTempPath = tempPath;
|
||||
ApplicationPhysicalPath = tempPath; // same location for now
|
||||
}
|
||||
|
||||
public string SiteName => "UmbracoIntegrationTests";
|
||||
|
||||
public string ApplicationId { get; } = Guid.NewGuid().ToString();
|
||||
|
||||
public string ApplicationPhysicalPath { get; private set; }
|
||||
|
||||
public string LocalTempPath { get; private set; }
|
||||
|
||||
public string ApplicationVirtualPath => "/";
|
||||
|
||||
public bool IsDebugMode => true;
|
||||
|
||||
public bool IsHosted => false;
|
||||
|
||||
public Version IISVersion => new Version(0, 0); // TODO not necessary IIS
|
||||
|
||||
public string MapPath(string path) => Path.Combine(ApplicationPhysicalPath, path);
|
||||
|
||||
public string ToAbsolute(string virtualPath, string root) => virtualPath.TrimStart('~');
|
||||
|
||||
public void RegisterObject(IRegisteredObject registeredObject)
|
||||
{
|
||||
}
|
||||
|
||||
public void UnregisterObject(IRegisteredObject registeredObject)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using Umbraco.Core.Runtime;
|
||||
|
||||
namespace Umbraco.Tests.Integration.Infrastructure
|
||||
{
|
||||
public class TestUmbracoBootPermissionChecker : IUmbracoBootPermissionChecker
|
||||
{
|
||||
public void ThrowIfNotPermissions()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -84,7 +84,7 @@
|
||||
<PackageReference Include="HtmlAgilityPack">
|
||||
<Version>1.8.14</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="LightInject" Version="5.4.0" />
|
||||
<PackageReference Include="LightInject" Version="6.3.2" />
|
||||
<PackageReference Include="LightInject.Annotation" Version="1.1.0" />
|
||||
<PackageReference Include="Lucene.Net.Contrib" Version="3.0.3" />
|
||||
<PackageReference Include="Microsoft.AspNet.Identity.Core" Version="2.2.2" />
|
||||
@@ -210,7 +210,6 @@
|
||||
<Compile Include="Services\CachedDataTypeServiceTests.cs" />
|
||||
<Compile Include="Services\ConsentServiceTests.cs" />
|
||||
<Compile Include="Services\SectionServiceTests.cs" />
|
||||
<Compile Include="TestHelpers\ConsoleLogger.cs" />
|
||||
<Compile Include="TestHelpers\ControllerTesting\AuthenticateEverythingExtensions.cs" />
|
||||
<Compile Include="TestHelpers\ControllerTesting\AuthenticateEverythingMiddleware.cs" />
|
||||
<Compile Include="TestHelpers\ControllerTesting\SpecificAssemblyResolver.cs" />
|
||||
|
||||
@@ -83,9 +83,10 @@ namespace Umbraco.Web.BackOffice.AspNetCore
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TODO: This may need to take into account ~/ paths which means the ApplicationVirtualPath and is this the content root or web root?
|
||||
public string MapPath(string path) => Path.Combine(_webHostEnvironment.WebRootPath, path);
|
||||
|
||||
// TODO: Need to take into account 'root' here
|
||||
public string ToAbsolute(string virtualPath, string root)
|
||||
{
|
||||
if (Uri.TryCreate(virtualPath, UriKind.Absolute, out _))
|
||||
|
||||
@@ -71,7 +71,7 @@
|
||||
<PackageReference Include="ImageProcessor">
|
||||
<Version>2.7.0.100</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="LightInject" Version="5.4.0" />
|
||||
<PackageReference Include="LightInject" Version="6.3.2" />
|
||||
<PackageReference Include="LightInject.Annotation" Version="1.1.0" />
|
||||
<PackageReference Include="LightInject.Mvc" Version="2.0.0" />
|
||||
<PackageReference Include="LightInject.Web">
|
||||
|
||||
Reference in New Issue
Block a user