diff --git a/src/Policy/IBuildKeyMappingPolicy.cs b/src/Policy/IBuildKeyMappingPolicy.cs deleted file mode 100644 index 3e8b3d3c..00000000 --- a/src/Policy/IBuildKeyMappingPolicy.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; -using Unity.Builder; - -namespace Unity.Policy -{ - /// - /// Represents a builder policy for mapping build keys. - /// - public interface IBuildKeyMappingPolicy - { - /// - /// Maps the build key. - /// - /// Current build context. Used for contextual information - /// if writing a more sophisticated mapping. This parameter can be null - /// (called when getting container registrations). - /// The new build key. - Type Map(ref BuilderContext context); - - /// - /// Instructs engine to resolve type rather than build it - /// - bool RequireBuild { get; } - } -} diff --git a/src/Unity.Container.csproj b/src/Unity.Container.csproj index 38a89035..6fcc464b 100644 --- a/src/Unity.Container.csproj +++ b/src/Unity.Container.csproj @@ -71,9 +71,4 @@ - - - - - diff --git a/src/UnityContainer.IUnityContainer.cs b/src/UnityContainer.IUnityContainer.cs index c798686b..37ee7b32 100644 --- a/src/UnityContainer.IUnityContainer.cs +++ b/src/UnityContainer.IUnityContainer.cs @@ -87,6 +87,14 @@ namespace Unity return this; } + /// + IUnityContainer IUnityContainer.RegisterType(IEnumerable interfaces, Type implementationType, string name, + LifetimeManager lifetimeManager, params InjectionMember[] injectionMembers) + { + throw new NotImplementedException(); + } + + #endregion diff --git a/tests/Performance/Performance.csproj b/tests/Performance/Performance.csproj index 1324df4f..1379be17 100644 --- a/tests/Performance/Performance.csproj +++ b/tests/Performance/Performance.csproj @@ -3,6 +3,9 @@ Exe net461 + true + ..\..\src\package.snk + false diff --git a/tests/Performance/Tests/Compiled.cs b/tests/Performance/Tests/Compiled.cs index 97c68ccf..3484b8a3 100644 --- a/tests/Performance/Tests/Compiled.cs +++ b/tests/Performance/Tests/Compiled.cs @@ -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(); _container.RegisterType(); _container.RegisterType("1"); _container.RegisterType("2", Invoke.Factory(c => new Foo())); + _container.RegisterType("3", Invoke.Factory((ref BuilderContext c) => new Foo())); } [Benchmark(Description = "Resolve ")] - public object IUnityContainer() => _container.Resolve(typeof(IUnityContainer), null); + public object UnityContainer() => _container.Resolve(typeof(IUnityContainer), null); [Benchmark(Description = "Compiled (unregistered)")] public object Unregistered() => _container.Resolve(typeof(object), null); @@ -35,8 +37,11 @@ namespace Runner.Tests [Benchmark(Description = "Compiled (registered)")] public object Mapping() => _container.Resolve(typeof(IFoo), null); + [Benchmark(Description = "Compiled (legacy)")] + public object LegacyFactory() => _container.Resolve(typeof(IFoo), "2"); + [Benchmark(Description = "Compiled (factory)")] - public object Factory() => _container.Resolve(typeof(IFoo), "2"); + public object Factory() => _container.Resolve(typeof(IFoo), "3"); [Benchmark(Description = "Compiled (registered)")] public object Array() => _container.Resolve(typeof(IFoo[]), null); diff --git a/tests/Performance/Tests/PreCompiled.cs b/tests/Performance/Tests/PreCompiled.cs index afd9708d..004a349d 100644 --- a/tests/Performance/Tests/PreCompiled.cs +++ b/tests/Performance/Tests/PreCompiled.cs @@ -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(); _container.RegisterType(); _container.RegisterType("1"); _container.RegisterType("2", Invoke.Factory(c => new Foo())); + _container.RegisterType("3", Invoke.Factory((ref BuilderContext c) => new Foo())); for (var i = 0; i < 3; i++) { @@ -29,11 +31,12 @@ namespace Runner.Tests _container.Resolve(); _container.Resolve("1"); _container.Resolve("2"); + _container.Resolve("3"); } } [Benchmark(Description = "Resolve ")] - public object IUnityContainer() => _container.Resolve(typeof(IUnityContainer), null); + public object UnityContainer() => _container.Resolve(typeof(IUnityContainer), null); [Benchmark(Description = "PreCompiled (pre-built)")] public object Unregistered() => _container.Resolve(typeof(object), null); @@ -44,8 +47,11 @@ namespace Runner.Tests [Benchmark(Description = "PreCompiled (pre-built)")] public object Mapping() => _container.Resolve(typeof(IFoo), null); - [Benchmark(Description = "PreCompiled (factory)")] - public object Factory() => _container.Resolve(typeof(IFoo), "2"); + [Benchmark(Description = "Compiled (legacy)")] + public object LegacyFactory() => _container.Resolve(typeof(IFoo), "2"); + + [Benchmark(Description = "Compiled (factory)")] + public object Factory() => _container.Resolve(typeof(IFoo), "3"); [Benchmark(Description = "PreCompiled (pre-built)")] public object Array() => _container.Resolve(typeof(IFoo[]), null); diff --git a/tests/Performance/Tests/PreResolved.cs b/tests/Performance/Tests/PreResolved.cs index ccc0272d..78751210 100644 --- a/tests/Performance/Tests/PreResolved.cs +++ b/tests/Performance/Tests/PreResolved.cs @@ -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(); _container.RegisterType(); _container.RegisterType("1"); _container.RegisterType("2", Invoke.Factory(c => new Foo())); + _container.RegisterType("3", Invoke.Factory((ref BuilderContext c) => new Foo())); for (var i = 0; i < 3; i++) { @@ -29,11 +31,12 @@ namespace Runner.Tests _container.Resolve(); _container.Resolve("1"); _container.Resolve("2"); + _container.Resolve("3"); } } [Benchmark(Description = "Resolve ")] - public object IUnityContainer() => _container.Resolve(typeof(IUnityContainer), null); + public object UnityContainer() => _container.Resolve(typeof(IUnityContainer), null); [Benchmark(Description = "PreResolved (optimized)")] public object Unregistered() => _container.Resolve(typeof(object), null); @@ -44,8 +47,11 @@ namespace Runner.Tests [Benchmark(Description = "PreResolved (optimized)")] public object Mapping() => _container.Resolve(typeof(IFoo), null); - [Benchmark(Description = "PreResolved (factory)")] - public object Factory() => _container.Resolve(typeof(IFoo), "2"); + [Benchmark(Description = "Compiled (legacy)")] + public object LegacyFactory() => _container.Resolve(typeof(IFoo), "2"); + + [Benchmark(Description = "Compiled (factory)")] + public object Factory() => _container.Resolve(typeof(IFoo), "3"); [Benchmark(Description = "PreResolved (optimized)")] public object Array() => _container.Resolve(typeof(IFoo[]), null); diff --git a/tests/Performance/Tests/Registration.cs b/tests/Performance/Tests/Registration.cs index 38e39452..6cee4f8a 100644 --- a/tests/Performance/Tests/Registration.cs +++ b/tests/Performance/Tests/Registration.cs @@ -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); diff --git a/tests/Performance/Tests/Resolved.cs b/tests/Performance/Tests/Resolved.cs index 30a58572..a4fd01d9 100644 --- a/tests/Performance/Tests/Resolved.cs +++ b/tests/Performance/Tests/Resolved.cs @@ -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(); _container.RegisterType(); _container.RegisterType("1"); _container.RegisterType("2", Invoke.Factory(c => new Foo())); + _container.RegisterType("3", Invoke.Factory((ref BuilderContext c) => new Foo())); } [Benchmark(Description = "Resolve ")] - public object IUnityContainer() => _container.Resolve(typeof(IUnityContainer), null); + public object UnityContainer() => _container.Resolve(typeof(IUnityContainer), null); [Benchmark(Description = "Resolved (unregistered)")] public object Unregistered() => _container.Resolve(typeof(object), null); @@ -35,8 +37,11 @@ namespace Runner.Tests [Benchmark(Description = "Resolved (registered)")] public object Mapping() => _container.Resolve(typeof(IFoo), null); - [Benchmark(Description = "Resolved (factory)")] - public object Factory() => _container.Resolve(typeof(IFoo), "2"); + [Benchmark(Description = "Compiled (legacy)")] + public object LegacyFactory() => _container.Resolve(typeof(IFoo), "2"); + + [Benchmark(Description = "Compiled (factory)")] + public object Factory() => _container.Resolve(typeof(IFoo), "3"); [Benchmark(Description = "Resolved (registered)")] public object Array() => _container.Resolve(typeof(IFoo[]), null); diff --git a/tests/Unity.Tests/Lifetime/LifetimeFixture.cs b/tests/Unity.Tests/Lifetime/LifetimeFixture.cs index 25aa276f..f9f896a1 100644 --- a/tests/Unity.Tests/Lifetime/LifetimeFixture.cs +++ b/tests/Unity.Tests/Lifetime/LifetimeFixture.cs @@ -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());