From dcfad4285ecec2bcdec19788fa7782a50c8a5866 Mon Sep 17 00:00:00 2001 From: osoykan Date: Fri, 14 Jul 2017 21:37:06 +0300 Subject: [PATCH 1/3] nuget packages are updated --- .../Autofac.Extras.IocManager.DynamicProxy.csproj | 2 +- .../Autofac.Extras.IocManager.TestBase.csproj | 2 +- .../Autofac.Extras.IocManager.Tests.csproj | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Autofac.Extras.IocManager.DynamicProxy/Autofac.Extras.IocManager.DynamicProxy.csproj b/src/Autofac.Extras.IocManager.DynamicProxy/Autofac.Extras.IocManager.DynamicProxy.csproj index eeeae44..b081e0d 100644 --- a/src/Autofac.Extras.IocManager.DynamicProxy/Autofac.Extras.IocManager.DynamicProxy.csproj +++ b/src/Autofac.Extras.IocManager.DynamicProxy/Autofac.Extras.IocManager.DynamicProxy.csproj @@ -33,7 +33,7 @@ - + diff --git a/test/Autofac.Extras.IocManager.TestBase/Autofac.Extras.IocManager.TestBase.csproj b/test/Autofac.Extras.IocManager.TestBase/Autofac.Extras.IocManager.TestBase.csproj index fbd88fe..20b9767 100644 --- a/test/Autofac.Extras.IocManager.TestBase/Autofac.Extras.IocManager.TestBase.csproj +++ b/test/Autofac.Extras.IocManager.TestBase/Autofac.Extras.IocManager.TestBase.csproj @@ -14,7 +14,7 @@ - + diff --git a/test/Autofac.Extras.IocManager.Tests/Autofac.Extras.IocManager.Tests.csproj b/test/Autofac.Extras.IocManager.Tests/Autofac.Extras.IocManager.Tests.csproj index 881a70f..32b6ef9 100644 --- a/test/Autofac.Extras.IocManager.Tests/Autofac.Extras.IocManager.Tests.csproj +++ b/test/Autofac.Extras.IocManager.Tests/Autofac.Extras.IocManager.Tests.csproj @@ -11,7 +11,7 @@ - + From 9c36762aabacab2081b2092b6a61b11e5b3319cd Mon Sep 17 00:00:00 2001 From: osoykan Date: Fri, 14 Jul 2017 21:38:27 +0300 Subject: [PATCH 2/3] version incremented 3.1.1 --- common.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common.props b/common.props index f68cd4e..7c717df 100644 --- a/common.props +++ b/common.props @@ -1,6 +1,6 @@ - 3.1.0 + 3.1.1 True $(NoWarn);CS1591 https://raw.githubusercontent.com/osoykan/Stove/master/stove.png From a19c9d1ff132c60906cb6ce4fc712342806f995c Mon Sep 17 00:00:00 2001 From: osoykan Date: Fri, 14 Jul 2017 22:06:33 +0300 Subject: [PATCH 3/3] BeforeRegistrationCompletedEvent implemented #29 --- .../BeforeRegistrationCompletedEventArgs.cs | 14 +++++++ .../IServiceRegistration.cs | 5 +++ .../ServiceRegistration.cs | 40 +++++++++++-------- .../LastChanceOfRegistrationEvent_Tests.cs | 26 ++++++++---- 4 files changed, 60 insertions(+), 25 deletions(-) create mode 100644 src/Autofac.Extras.IocManager/BeforeRegistrationCompletedEventArgs.cs diff --git a/src/Autofac.Extras.IocManager/BeforeRegistrationCompletedEventArgs.cs b/src/Autofac.Extras.IocManager/BeforeRegistrationCompletedEventArgs.cs new file mode 100644 index 0000000..f01f994 --- /dev/null +++ b/src/Autofac.Extras.IocManager/BeforeRegistrationCompletedEventArgs.cs @@ -0,0 +1,14 @@ +using System; + +namespace Autofac.Extras.IocManager +{ + public class BeforeRegistrationCompletedEventArgs : EventArgs + { + public BeforeRegistrationCompletedEventArgs(ContainerBuilder containerBuilder) + { + this.ContainerBuilder = containerBuilder; + } + + public ContainerBuilder ContainerBuilder { get; } + } +} diff --git a/src/Autofac.Extras.IocManager/IServiceRegistration.cs b/src/Autofac.Extras.IocManager/IServiceRegistration.cs index 51c1083..21ab52e 100644 --- a/src/Autofac.Extras.IocManager/IServiceRegistration.cs +++ b/src/Autofac.Extras.IocManager/IServiceRegistration.cs @@ -26,6 +26,11 @@ public interface IServiceRegistration /// event EventHandler OnRegistering; + /// + /// Occurs when [before registration completed]. + /// + event EventHandler BeforeRegistrationCompleted; + /// /// Registers the specified lifetime. /// diff --git a/src/Autofac.Extras.IocManager/ServiceRegistration.cs b/src/Autofac.Extras.IocManager/ServiceRegistration.cs index 5cfafd6..afc07ca 100644 --- a/src/Autofac.Extras.IocManager/ServiceRegistration.cs +++ b/src/Autofac.Extras.IocManager/ServiceRegistration.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.ComponentModel; using System.Linq; using System.Reflection; @@ -66,6 +65,11 @@ public ServiceRegistration(ContainerBuilder containerBuilder) /// public event EventHandler OnRegistering; + /// + /// Occurs when [before registration completed]. + /// + public event EventHandler BeforeRegistrationCompleted; + /// /// Registers the specified lifetime. /// @@ -354,14 +358,14 @@ public void RegisterIfAbsent(Type serviceType, Type implementationType, Lifetime .IfNotRegistered(serviceType); _containerBuilder.Register(c => c.Resolve(implementationType)) - .As(serviceType) - .WithPropertyInjection() - .OnActivating(args => - { - object instance = _decoratorService.Decorate(args.Instance, new ResolverContext(new Resolver(args.Context))); - args.ReplaceInstance(instance); - }) - .IfNotRegistered(serviceType); + .As(serviceType) + .WithPropertyInjection() + .OnActivating(args => + { + object instance = _decoratorService.Decorate(args.Instance, new ResolverContext(new Resolver(args.Context))); + args.ReplaceInstance(instance); + }) + .IfNotRegistered(serviceType); registration.ApplyLifeStyle(lifetime); } @@ -596,6 +600,8 @@ public void RegisterAssemblyAsClosedTypesOf( /// public IRootResolver CreateResolver(bool ignoreStartableComponents = false) { + BeforeRegistrationCompleted?.Invoke(this, new BeforeRegistrationCompletedEventArgs(_containerBuilder)); + IContainer container = _containerBuilder.Build(ignoreStartableComponents ? ContainerBuildOptions.IgnoreStartableComponents : ContainerBuildOptions.None); _rootResolver = new RootResolver(container); @@ -654,10 +660,10 @@ internal void RegisterApplyingLifetime(ContainerBuilder builder, Type AddStartableIfPossible(typeToRegister, defaultGenerics); OnRegistering?.Invoke(this, new OnRegisteringEventArgs(_containerBuilder, typeToRegister, defaultGenerics.ToArray(), FindLifetime(typeof(TLifetime)))); builder.RegisterGeneric(typeToRegister) - .As(defaultGenerics.ToArray()) - .AsSelf() - .WithPropertyInjection() - .ApplyLifeStyle(typeof(TLifetime)); + .As(defaultGenerics.ToArray()) + .AsSelf() + .WithPropertyInjection() + .ApplyLifeStyle(typeof(TLifetime)); } else { @@ -665,10 +671,10 @@ internal void RegisterApplyingLifetime(ContainerBuilder builder, Type AddStartableIfPossible(typeToRegister, defaults); OnRegistering?.Invoke(this, new OnRegisteringEventArgs(_containerBuilder, typeToRegister, defaults.ToArray(), FindLifetime(typeof(TLifetime)))); builder.RegisterType(typeToRegister) - .As(defaults.ToArray()) - .AsSelf() - .WithPropertyInjection() - .ApplyLifeStyle(typeof(TLifetime)); + .As(defaults.ToArray()) + .AsSelf() + .WithPropertyInjection() + .ApplyLifeStyle(typeof(TLifetime)); } } diff --git a/test/Autofac.Extras.IocManager.Tests/LastChanceOfRegistrationEvent_Tests.cs b/test/Autofac.Extras.IocManager.Tests/LastChanceOfRegistrationEvent_Tests.cs index 049871c..2253fd8 100644 --- a/test/Autofac.Extras.IocManager.Tests/LastChanceOfRegistrationEvent_Tests.cs +++ b/test/Autofac.Extras.IocManager.Tests/LastChanceOfRegistrationEvent_Tests.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Reflection; +using System.Reflection; using Autofac.Extras.IocManager.TestBase; @@ -15,20 +13,32 @@ public class LastChanceOfRegistrationEvent_Tests : TestBaseWithIocBuilder [Fact] public void test() { - var dbContexts = new List(); - Building(builder => { builder.RegisterServices(r => { r.OnConventionalRegistering += (sender, args) => { }; - r.OnRegistering += (sender, args) => + r.OnRegistering += (sender, args) => { args.ContainerBuilder.RegisterType().As().AsSelf(); }; + + r.RegisterAssemblyByConvention(typeof(LastChanceOfRegistrationEvent_Tests).GetTypeInfo().Assembly); + }); + }); + + LocalIocManager.Resolve().ShouldNotBeNull(); + } + + [Fact] + public void before_registration_completed_should_register_last_chance() + { + Building(builder => + { + builder.RegisterServices(r => + { + r.BeforeRegistrationCompleted += (sender, args) => { args.ContainerBuilder.RegisterType().As().AsSelf(); }; - - r.RegisterAssemblyByConvention(typeof(LastChanceOfRegistrationEvent_Tests).GetTypeInfo().Assembly); }); });