public static Container Create(ApplicationBootstrapConfig config) { var container = new Container(); container.Options.AllowOverridingRegistrations = true; container.Register<IServiceProvider>(() => container); container.RegisterMediator(config.Assemblies.ToArray()); container.Register<ITaskRepository, EfTaskRepository>(); container.Register<IUnitOfWork>(() => new UnitOfWork(new MyAppContext().AsCommandContext()), config.UnitOfWorkLifestyle); container.Register<IQueryContext>(() => new QueryContext(new MyAppContext().AsQueryContext()), config.UnitOfWorkLifestyle); container.RegisterSingleton<IConnectionProvider, ConnectionProvider>(); container.RegisterCollection(typeof(IValidator<>), config.Assemblies); var commandDecorators = new List<Type> { typeof(UnitOfWorkHandler<,>), typeof(TransactionHandler<,>), typeof(ValidatorHandler<,>), typeof(LogHandler<,>) }; container.RegisterRequestHandlerDecorators(GetCommandDecorators(), context => { var argument = context.ServiceType.GetGenericArguments()[0]; return argument.Namespace.EndsWith("Commands"); }); container.RegisterRequestHandlerDecorators(GetQueryDecorators(), context => { var argument = context.ServiceType.GetGenericArguments()[0]; return argument.Namespace.EndsWith("Queries"); }); return container; }
// TODO: Use Assembly Discovery.. void SetupContainer(Func<ISteamApi> steamApi) { _assemblies = new[] {Assembly.GetExecutingAssembly()}; _container = new Container(); _container.Options.DefaultScopedLifestyle = new ExecutionContextScopeLifestyle(); _container.RegisterSingleton<ICheatImpl, CheatImpl>(); _container.RegisterSingleton<IExceptionHandler, UnhandledExceptionHandler>(); _container.RegisterSingleton<IActionDispatcher>( () => new ActionDispatcher(_container.GetInstance<IMediator>(), null)); BootstrapperBridge.RegisterMessageBus(_container); _container.RegisterSingleton<IMessageBusProxy, MessageBusProxy>(); _container.RegisterSingleton<ISteamHelper>(SteamHelper.Create()); _container.RegisterPlugins<IHandleExceptionPlugin>(_assemblies, Lifestyle.Singleton); _container.RegisterSingleton<SteamSession.SteamSessionFactory>(); _container.RegisterSingleton<ISteamSessionFactory>(_container.GetInstance<SteamSession.SteamSessionFactory>); _container.RegisterSingleton<ISteamSessionLocator>(_container.GetInstance<SteamSession.SteamSessionFactory>); _container.RegisterSingleton<IServiceMessenger, ServiceMessenger>(); _container.RegisterSingleton<ISteamDownloader, SteamDownloader>(); _container.RegisterSingleton<Api.Services.ISteamApi, SteamApi>(); _container.RegisterSingleton(steamApi); _container.RegisterSingleton<IEventStorage, EventStorage>(); _container.RegisterSingleton<ISafeCallFactory, SafeCallFactory>(); _container.RegisterValidation(_assemblies); _container.RegisterMediator(_assemblies); _container.RegisterDecorator<IMediator, MediatorLoggingDecorator>(); _container.Register<IRequestScope, RequestScope>(Lifestyle.Scoped); _container.RegisterSingleton<IRequestScopeLocator, RequestScopeService>(); }