This commit is contained in:
Eugene Sadovoi 2019-01-01 23:23:30 -05:00
Родитель d7bd3e2e18
Коммит 32d44f5e68
10 изменённых файлов: 53 добавлений и 49 удалений

Просмотреть файл

@ -1,25 +0,0 @@
using System;
using Unity.Builder;
namespace Unity.Policy
{
/// <summary>
/// Represents a builder policy for mapping build keys.
/// </summary>
public interface IBuildKeyMappingPolicy
{
/// <summary>
/// Maps the build key.
/// </summary>
/// <param name="context">Current build context. Used for contextual information
/// if writing a more sophisticated mapping. This parameter can be null
/// (called when getting container registrations).</param>
/// <returns>The new build key.</returns>
Type Map(ref BuilderContext context);
/// <summary>
/// Instructs engine to resolve type rather than build it
/// </summary>
bool RequireBuild { get; }
}
}

Просмотреть файл

@ -71,9 +71,4 @@
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.5.2" />
</ItemGroup>
<ItemGroup>
<Folder Include="Policy\BuildPlanCreator\" />
</ItemGroup>
</Project>

Просмотреть файл

@ -87,6 +87,14 @@ namespace Unity
return this;
}
/// <inheritdoc />
IUnityContainer IUnityContainer.RegisterType(IEnumerable<Type> interfaces, Type implementationType, string name,
LifetimeManager lifetimeManager, params InjectionMember[] injectionMembers)
{
throw new NotImplementedException();
}
#endregion

Просмотреть файл

@ -3,6 +3,9 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net461</TargetFramework>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\src\package.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
</PropertyGroup>
<ItemGroup>

Просмотреть файл

@ -2,6 +2,7 @@
using Runner.Setup;
using System.Collections.Generic;
using Unity;
using Unity.Builder;
namespace Runner.Tests
{
@ -15,16 +16,17 @@ namespace Runner.Tests
[IterationSetup]
public virtual void SetupContainer()
{
_container = new UnityContainer(UnityContainer.BuildStrategy.Compiled);
_container = new UnityContainer(Unity.UnityContainer.BuildStrategy.Compiled);
_container.RegisterType<Poco>();
_container.RegisterType<IFoo, Foo>();
_container.RegisterType<IFoo, Foo>("1");
_container.RegisterType<IFoo>("2", Invoke.Factory(c => new Foo()));
_container.RegisterType<IFoo>("3", Invoke.Factory((ref BuilderContext c) => new Foo()));
}
[Benchmark(Description = "Resolve<IUnityContainer> ")]
public object IUnityContainer() => _container.Resolve(typeof(IUnityContainer), null);
public object UnityContainer() => _container.Resolve(typeof(IUnityContainer), null);
[Benchmark(Description = "Compiled<object> (unregistered)")]
public object Unregistered() => _container.Resolve(typeof(object), null);
@ -35,8 +37,11 @@ namespace Runner.Tests
[Benchmark(Description = "Compiled<IService> (registered)")]
public object Mapping() => _container.Resolve(typeof(IFoo), null);
[Benchmark(Description = "Compiled<IService> (legacy)")]
public object LegacyFactory() => _container.Resolve(typeof(IFoo), "2");
[Benchmark(Description = "Compiled<IService> (factory)")]
public object Factory() => _container.Resolve(typeof(IFoo), "2");
public object Factory() => _container.Resolve(typeof(IFoo), "3");
[Benchmark(Description = "Compiled<IService[]> (registered)")]
public object Array() => _container.Resolve(typeof(IFoo[]), null);

Просмотреть файл

@ -2,6 +2,7 @@
using Runner.Setup;
using System.Collections.Generic;
using Unity;
using Unity.Builder;
namespace Runner.Tests
{
@ -15,12 +16,13 @@ namespace Runner.Tests
[IterationSetup]
public virtual void SetupContainer()
{
_container = new UnityContainer(UnityContainer.BuildStrategy.Compiled);
_container = new UnityContainer(Unity.UnityContainer.BuildStrategy.Compiled);
_container.RegisterType<Poco>();
_container.RegisterType<IFoo, Foo>();
_container.RegisterType<IFoo, Foo>("1");
_container.RegisterType<IFoo>("2", Invoke.Factory(c => new Foo()));
_container.RegisterType<IFoo>("3", Invoke.Factory((ref BuilderContext c) => new Foo()));
for (var i = 0; i < 3; i++)
{
@ -29,11 +31,12 @@ namespace Runner.Tests
_container.Resolve<IFoo>();
_container.Resolve<IFoo>("1");
_container.Resolve<IFoo>("2");
_container.Resolve<IFoo>("3");
}
}
[Benchmark(Description = "Resolve<IUnityContainer> ")]
public object IUnityContainer() => _container.Resolve(typeof(IUnityContainer), null);
public object UnityContainer() => _container.Resolve(typeof(IUnityContainer), null);
[Benchmark(Description = "PreCompiled<object> (pre-built)")]
public object Unregistered() => _container.Resolve(typeof(object), null);
@ -44,8 +47,11 @@ namespace Runner.Tests
[Benchmark(Description = "PreCompiled<IService> (pre-built)")]
public object Mapping() => _container.Resolve(typeof(IFoo), null);
[Benchmark(Description = "PreCompiled<IService> (factory)")]
public object Factory() => _container.Resolve(typeof(IFoo), "2");
[Benchmark(Description = "Compiled<IService> (legacy)")]
public object LegacyFactory() => _container.Resolve(typeof(IFoo), "2");
[Benchmark(Description = "Compiled<IService> (factory)")]
public object Factory() => _container.Resolve(typeof(IFoo), "3");
[Benchmark(Description = "PreCompiled<IService[]> (pre-built)")]
public object Array() => _container.Resolve(typeof(IFoo[]), null);

Просмотреть файл

@ -2,6 +2,7 @@
using Runner.Setup;
using System.Collections.Generic;
using Unity;
using Unity.Builder;
namespace Runner.Tests
{
@ -15,12 +16,13 @@ namespace Runner.Tests
[IterationSetup]
public virtual void SetupContainer()
{
_container = new UnityContainer(UnityContainer.BuildStrategy.Resolved);
_container = new UnityContainer(Unity.UnityContainer.BuildStrategy.Resolved);
_container.RegisterType<Poco>();
_container.RegisterType<IFoo, Foo>();
_container.RegisterType<IFoo, Foo>("1");
_container.RegisterType<IFoo>("2", Invoke.Factory(c => new Foo()));
_container.RegisterType<IFoo>("3", Invoke.Factory((ref BuilderContext c) => new Foo()));
for (var i = 0; i < 3; i++)
{
@ -29,11 +31,12 @@ namespace Runner.Tests
_container.Resolve<IFoo>();
_container.Resolve<IFoo>("1");
_container.Resolve<IFoo>("2");
_container.Resolve<IFoo>("3");
}
}
[Benchmark(Description = "Resolve<IUnityContainer> ")]
public object IUnityContainer() => _container.Resolve(typeof(IUnityContainer), null);
public object UnityContainer() => _container.Resolve(typeof(IUnityContainer), null);
[Benchmark(Description = "PreResolved<object> (optimized)")]
public object Unregistered() => _container.Resolve(typeof(object), null);
@ -44,8 +47,11 @@ namespace Runner.Tests
[Benchmark(Description = "PreResolved<IService> (optimized)")]
public object Mapping() => _container.Resolve(typeof(IFoo), null);
[Benchmark(Description = "PreResolved<IService> (factory)")]
public object Factory() => _container.Resolve(typeof(IFoo), "2");
[Benchmark(Description = "Compiled<IService> (legacy)")]
public object LegacyFactory() => _container.Resolve(typeof(IFoo), "2");
[Benchmark(Description = "Compiled<IService> (factory)")]
public object Factory() => _container.Resolve(typeof(IFoo), "3");
[Benchmark(Description = "PreResolved<IService[]> (optimized)")]
public object Array() => _container.Resolve(typeof(IFoo[]), null);

Просмотреть файл

@ -1,4 +1,5 @@
using BenchmarkDotNet.Attributes;
using System;
using BenchmarkDotNet.Attributes;
using Runner.Setup;
using System.Linq;
using Unity;
@ -19,7 +20,7 @@ namespace Runner.Tests
}
[Benchmark(Description = "Register (No Mapping)")]
public object Register() => _container.RegisterType(null, typeof(object), null, null);
public object Register() => _container.RegisterType((Type)null, typeof(object), null, null);
[Benchmark(Description = "Register Mapping")]
public object RegisterMapping() => _container.RegisterType(typeof(IFoo), typeof(Foo), null, null);

Просмотреть файл

@ -2,6 +2,7 @@
using Runner.Setup;
using System.Collections.Generic;
using Unity;
using Unity.Builder;
namespace Runner.Tests
{
@ -15,16 +16,17 @@ namespace Runner.Tests
[IterationSetup]
public virtual void SetupContainer()
{
_container = new UnityContainer(UnityContainer.BuildStrategy.Resolved);
_container = new UnityContainer(Unity.UnityContainer.BuildStrategy.Resolved);
_container.RegisterType<Poco>();
_container.RegisterType<IFoo, Foo>();
_container.RegisterType<IFoo, Foo>("1");
_container.RegisterType<IFoo>("2", Invoke.Factory(c => new Foo()));
_container.RegisterType<IFoo>("3", Invoke.Factory((ref BuilderContext c) => new Foo()));
}
[Benchmark(Description = "Resolve<IUnityContainer> ")]
public object IUnityContainer() => _container.Resolve(typeof(IUnityContainer), null);
public object UnityContainer() => _container.Resolve(typeof(IUnityContainer), null);
[Benchmark(Description = "Resolved<object> (unregistered)")]
public object Unregistered() => _container.Resolve(typeof(object), null);
@ -35,8 +37,11 @@ namespace Runner.Tests
[Benchmark(Description = "Resolved<IService> (registered)")]
public object Mapping() => _container.Resolve(typeof(IFoo), null);
[Benchmark(Description = "Resolved<IService> (factory)")]
public object Factory() => _container.Resolve(typeof(IFoo), "2");
[Benchmark(Description = "Compiled<IService> (legacy)")]
public object LegacyFactory() => _container.Resolve(typeof(IFoo), "2");
[Benchmark(Description = "Compiled<IService> (factory)")]
public object Factory() => _container.Resolve(typeof(IFoo), "3");
[Benchmark(Description = "Resolved<IService[]> (registered)")]
public object Array() => _container.Resolve(typeof(IFoo[]), null);

Просмотреть файл

@ -326,8 +326,8 @@ namespace Unity.Tests.v5.Lifetime
var aInstance = new EmailService();
uc.RegisterType(null, typeof(EmailService), null, new ContainerControlledLifetimeManager(), null);
uc.RegisterType(null, typeof(EmailService), "SetA", new ContainerControlledLifetimeManager(), null);
uc.RegisterType((Type)null, typeof(EmailService), null, new ContainerControlledLifetimeManager(), null);
uc.RegisterType((Type)null, typeof(EmailService), "SetA", new ContainerControlledLifetimeManager(), null);
uc.RegisterInstance(aInstance);
uc.RegisterInstance("hello", aInstance);
uc.RegisterInstance("hello", aInstance, new ExternallyControlledLifetimeManager());