private void _RegisterServicesIntoNinjectIoCContainer() { var ninjectIoCContainer = NinjectWebCommon.Bootstrapper.Kernel; CoreDddNhibernateBindings.SetUnitOfWorkLifeStyle(x => x.InRequestScope()); ninjectIoCContainer.Load( typeof(CoreDddBindings).Assembly, typeof(CoreDddNhibernateBindings).Assembly ); ninjectIoCContainer .Bind <INhibernateConfigurator>() .To <CoreDddSampleNhibernateConfigurator>() .InSingletonScope(); // register controllers ninjectIoCContainer.Bind(x => x .FromAssemblyContaining <HomeController>() .SelectAllClasses() .InheritedFrom <ControllerBase>() .BindAllInterfaces() .Configure(y => y.InTransientScope())); // register command handlers ninjectIoCContainer.Bind(x => x .FromAssemblyContaining <CreateNewShipCommandHandler>() .SelectAllClasses() .InheritedFrom(typeof(ICommandHandler <>)) .BindAllInterfaces() .Configure(y => y.InTransientScope())); // register query handlers ninjectIoCContainer.Bind(x => x .FromAssemblyContaining <GetShipsByNameQueryHandler>() .SelectAllClasses() .InheritedFrom(typeof(IQueryHandler <>)) .BindAllInterfaces() .Configure(y => y.InTransientScope())); // register domain event handlers ninjectIoCContainer.Bind(x => x .FromAssemblyContaining <ShipUpdatedDomainEventHandler>() .SelectAllClasses() .InheritedFrom(typeof(IDomainEventHandler <>)) .BindAllInterfaces() .Configure(y => y.InTransientScope())); UnitOfWorkHttpModule.Initialize( ninjectIoCContainer.Get <IUnitOfWorkFactory>(), isolationLevel: System.Data.IsolationLevel.ReadCommitted ); DomainEvents.Initialize( ninjectIoCContainer.Get <IDomainEventHandlerFactory>(), isDelayedDomainEventHandlingEnabled: true ); }
public static IKernel RegisterServicesIntoIoC() { var kernel = new StandardKernel(); CoreDddNhibernateBindings.SetUnitOfWorkLifeStyle(x => x.InThreadScope()); // todo: here should be "per rebus message" (see PerRebusMessage for CastleIoCRegistration); might not play nicely with async code kernel.Load( typeof(CoreDddBindings).Assembly, typeof(CoreDddNhibernateBindings).Assembly, typeof(EmailSenderBindings).Assembly, typeof(QueryHandlerBindings).Assembly, typeof(EmailMakerNhibernateBindings).Assembly ); IoC.Initialize(new NinjectContainer(kernel)); return(kernel); }
public static void _RegisterServicesIntoNinjectIoCContainer() { var ninjectIoCContainer = NinjectWebCommon.Bootstrapper.Kernel; CoreDddNhibernateBindings.SetUnitOfWorkLifeStyle(x => x.InRequestScope()); ninjectIoCContainer.Load( typeof(CoreDddBindings).Assembly, typeof(CoreDddNhibernateBindings).Assembly ); ninjectIoCContainer .Bind <INhibernateConfigurator>() .To <CoreDddSampleNhibernateConfigurator>() .InSingletonScope(); // register MVC controllers ninjectIoCContainer.Bind(x => x .FromAssemblyContaining <HomeController>() .SelectAllClasses() .InheritedFrom <ControllerBase>() .BindAllInterfaces() .Configure(y => y.InTransientScope())); // register Web API controllers ninjectIoCContainer.Bind(x => x .FromAssemblyContaining <ShipController>() .SelectAllClasses() .InheritedFrom <ApiController>() .BindAllInterfaces() .Configure(y => y.InTransientScope())); // register command handlers ninjectIoCContainer.Bind(x => x .FromAssemblyContaining <CreateNewShipCommandHandler>() .SelectAllClasses() .InheritedFrom(typeof(ICommandHandler <>)) .BindAllInterfaces() .Configure(y => y.InTransientScope())); // register query handlers ninjectIoCContainer.Bind(x => x .FromAssemblyContaining <GetShipsByNameQueryHandler>() .SelectAllClasses() .InheritedFrom(typeof(IQueryHandler <>)) .BindAllInterfaces() .Configure(y => y.InTransientScope())); // register domain event handlers ninjectIoCContainer.Bind(x => x .FromAssemblyContaining <ShipUpdatedDomainEventHandler>() .SelectAllClasses() .InheritedFrom(typeof(IDomainEventHandler <>)) .BindAllInterfaces() .Configure(y => y.InTransientScope())); Action <TransactionScope> transactionScopeEnlistmentAction = transactionScope => { // enlist custom resource manager into the transaction scope }; TransactionScopeUnitOfWorkHttpModule.Initialize( ninjectIoCContainer.Get <IUnitOfWorkFactory>(), transactionScopeEnlistmentAction: transactionScopeEnlistmentAction, isolationLevel: System.Transactions.IsolationLevel.ReadCommitted ); DomainEvents.Initialize(ninjectIoCContainer.Get <IDomainEventHandlerFactory>()); }