public IApplicationController RegisterView <TView, TImplementation>() where TImplementation : class, TView where TView : IView { _container.Register <TView, TImplementation>(); return(this); }
public void RegisterComponents(IMongoClient client) { RegisterDefaults(); _containerAdapter.RegisterInstance<IMongoClient>(client); _containerAdapter.Register<IMigrationService, MigrationService>(); }
void FillOutMissingRegistrationsWithDefaults() { if (!containerAdapter.HasImplementationOf(typeof(IStoreSubscriptions))) { containerAdapter.RegisterInstance(new InMemorySubscriptionStorage(), typeof(IStoreSubscriptions)); } if (!containerAdapter.HasImplementationOf(typeof(IStoreSagaData))) { containerAdapter.RegisterInstance(new InMemorySagaPersister(), typeof(IStoreSagaData)); } if (!containerAdapter.HasImplementationOf(typeof(IDetermineDestination))) { containerAdapter.RegisterInstance(new ThrowingEndpointMapper(), typeof(IDetermineDestination)); } if (!containerAdapter.HasImplementationOf(typeof(ISerializeMessages))) { containerAdapter.RegisterInstance(new JsonMessageSerializer(), typeof(ISerializeMessages)); } if (!containerAdapter.HasImplementationOf(typeof(IInspectHandlerPipeline))) { containerAdapter.RegisterInstance(new TrivialPipelineInspector(), typeof(IInspectHandlerPipeline)); } containerAdapter.Register(typeof(RebusBus), Lifestyle.Singleton, typeof(IStartableBus), typeof(IBus), typeof(IAdvancedBus)); }
//Func<CustomUnitOfWorkSettings, ITransactionManager> getTransactionManager; /// <summary> /// Configures <see cref="UnitOfWorkScope"/> settings. /// </summary> /// <param name="containerAdapter">The <see cref="IContainerAdapter"/> instance.</param> public void Configure(IContainerAdapter containerAdapter) { var settings = new CustomUnitOfWorkSettings() { AutoCompleteScope = _autoCompleteScope, DefaultIsolation = _defaultIsolation }; containerAdapter.RegisterInstance(settings); containerAdapter.RegisterSingleton <IUnityUnitOfWorkManager, UnityUnitOfWorkManager>(); //containerAdapter.RegisterInstance<ITransactionManager>(getTransactionManager(settings)); containerAdapter.RegisterInstance <IUnitOfWorkGuid>(new UnitOfWorkGuid()); containerAdapter.RegisterSingleton <IUnitOfWorkScopeFactory, UnityUnitOfWorkScopeFactory>(); containerAdapter.Register <IUnitOfWorkScope, UnityUnitOfWorkScope>(); //UnitOfWorkSettings.AutoCompleteScope = _autoCompleteScope; //UnitOfWorkSettings.DefaultIsolation = _defaultIsolation; if (_useBusinessTransaction) { containerAdapter.RegisterSingleton <IBusinessTransactionObservable, BusinessTransactionSubjectWrapper>(); containerAdapter.RegisterSingleton <IBusinessTransactionSubscriber, BusinessTransactionSubjectWrapper>(); containerAdapter.RegisterInstance <IBusinessTransactionSubjectFactory>(new BusinessTransactionSubjectFactory(() => new BusinessTransactionSubject())); } else { var subject = new StubTransactionSubject(); containerAdapter.RegisterInstance <IBusinessTransactionObservable>(subject); containerAdapter.RegisterInstance <IBusinessTransactionSubscriber>(subject); containerAdapter.RegisterInstance <IBusinessTransactionSubjectFactory>(new BusinessTransactionSubjectFactory(() => subject)); } //IBusinessTransactionSubject subject = !_useBusinessTransaction? new StubTransactionSubject(): new BusinessTransactionSubjectWrapper(); //containerAdapter.RegisterInstance<IBusinessTransactionSubjectFactory>(new BusinessTransactionSubjectFactory(!_useBusinessTransaction ? () => subject : () => new BusinessTransactionSubject())); }
public void Configure(IContainerAdapter containerAdapter) { containerAdapter.Register <IVirtualPathUtilityService, VirtualPathUtilityService>(); //containerAdapter.Register<ILocalState, HttpLocalState>(); //containerAdapter.Register<ICacheState, HttpRuntimeCache>(); //containerAdapter.Register<ISessionState, HttpSessionState>(); }
void FillOutMissingRegistrationsWithDefaults() { if (!containerAdapter.HasImplementationOf(typeof(IStoreSubscriptions))) { containerAdapter.RegisterInstance(new InMemorySubscriptionStorage(), typeof(IStoreSubscriptions)); } if (!containerAdapter.HasImplementationOf(typeof(IStoreSagaData))) { containerAdapter.RegisterInstance(new InMemorySagaPersister(), typeof(IStoreSagaData)); } if (!containerAdapter.HasImplementationOf(typeof(IDetermineDestination))) { containerAdapter.RegisterInstance(new ThrowingEndpointMapper(), typeof(IDetermineDestination)); } if (!containerAdapter.HasImplementationOf(typeof(ISerializeMessages))) { containerAdapter.RegisterInstance(new BinaryMessageSerializer(), typeof(ISerializeMessages)); } if (!containerAdapter.HasImplementationOf(typeof(IInspectHandlerPipeline))) { containerAdapter.RegisterInstance(new TrivialPipelineInspector(), typeof(IInspectHandlerPipeline)); } if (!containerAdapter.HasImplementationOf(typeof(IStartableBus))) { if (containerAdapter.HasImplementationOf(typeof(IBus))) { throw new ConfigurationException(@" Detected that there was no IStartableBus configured, even though there is an IBus! If you want to work with the configuration API, and you want to register your some custom implementation of IBus and/or IStartableBus, please assume the full responsibility and register something that implements both! Registering only one of them will most likely lead to confusion some time in the future. "); } containerAdapter.Register(typeof(RebusBus), Lifestyle.Singleton, typeof(IStartableBus), typeof(IBus)); } else { if (!containerAdapter.HasImplementationOf(typeof(IBus))) { throw new ConfigurationException( @" Detected that there was no IBus configured, even though there is an IStartableBus! If you want to work with the configuration API, and you want to register your some custom implementation of IBus and/or IStartableBus, please assume the full responsibility and register something that implements both! Registering only one of them will most likely lead to confusion some time in the future. "); } } }
protected void CanRegisterOneFluentType(Func <IContainerAdapter> adapterFunc) { IContainerAdapter adapter = adapterFunc(); var registration = adapter.CreateComponentRegistration <ComponentRegistration>() .Register <ISuperDependantClass>() .As <DependantClass>(); adapter.Register(registration); Assert.AreEqual(typeof(DependantClass), adapter.Resolve <ISuperDependantClass>().GetType()); Assert.IsNull(adapter.TryResolve <IDependantClass>()); }
protected void CanRegisterFluentInstance(Func <IContainerAdapter> adapterFunc) { IContainerAdapter adapter = adapterFunc(); var returnClass = new DependantClass(); var registration = adapter.CreateComponentRegistration <ComponentRegistration>() .Register <ISuperDependantClass>() .Instance(returnClass); adapter.Register(registration); Assert.AreEqual(returnClass, adapter.Resolve <ISuperDependantClass>()); Assert.IsNull(adapter.TryResolve <IDependantClass>()); }
protected void CanRegisterFluentTypeWithLifetime(Func <IContainerAdapter> adapterFunc) { IContainerAdapter adapter = adapterFunc(); var registration = adapter.CreateComponentRegistration <ComponentRegistration>() .Register <IDependantClass, ISuperDependantClass>() .As <DependantClass>() .Lifetime(LifetimeScope.Singleton); adapter.Register(registration); Assert.AreEqual(adapter.Resolve <IDependantClass>().GetType(), adapter.Resolve <ISuperDependantClass>().GetType()); Assert.AreEqual(typeof(DependantClass), adapter.Resolve <ISuperDependantClass>().GetType()); Assert.AreEqual(typeof(DependantClass), adapter.Resolve <IDependantClass>().GetType()); }
/// <summary> /// Called by NCommon <see cref="Configure"/> to configure state storage. /// </summary> /// <param name="containerAdapter">The <see cref="IContainerAdapter"/> instance that can be /// used to register state storage components.</param> public void Configure(IContainerAdapter containerAdapter) { if (_customSessionType != null) { containerAdapter.Register(typeof(ISessionState), _customSessionType); } else { containerAdapter.Register <ISessionStateSelector, DefaultSessionStateSelector>(); containerAdapter.Register <ISessionState, SessionStateWrapper>(); } if (_customLocalStateType != null) { containerAdapter.Register(typeof(ILocalState), _customLocalStateType); } else { containerAdapter.Register <ILocalStateSelector, DefaultLocalStateSelector>(); containerAdapter.Register <ILocalState, LocalStateWrapper>(); } if (_customCacheType != null) { containerAdapter.Register(typeof(ICacheState), _customCacheType); } else { containerAdapter.Register <ICacheState, HttpRuntimeCache>(); } if (_customApplicationStateType != null) { containerAdapter.RegisterSingleton(typeof(IApplicationState), _customApplicationStateType); } else { containerAdapter.RegisterSingleton <IApplicationState, ApplicationState>(); } containerAdapter.Register <IState, State.Impl.State>(); }
protected void CanRegisterThreeNamedFluentTypes(Func <IContainerAdapter> adapterFunc) { IContainerAdapter adapter = adapterFunc(); var registration = adapter.CreateComponentRegistration <ComponentRegistration>() .Register <IDependantClass, ISuperDependantClass, IOtherDependantClass>() .As <DependantClass>() .Named("fred"); adapter.Register(registration); Assert.AreEqual(adapter.Resolve <IDependantClass>().GetType(), adapter.Resolve <ISuperDependantClass>().GetType()); Assert.AreEqual(typeof(DependantClass), adapter.Resolve <ISuperDependantClass>().GetType()); Assert.AreEqual(typeof(DependantClass), adapter.Resolve <IDependantClass>().GetType()); Assert.AreEqual(typeof(DependantClass), adapter.Resolve <IOtherDependantClass>().GetType()); }
void RegisterHandlersFrom(Assembly assembly, Predicate <Type> predicate) { var messageHandlers = assembly.GetTypes() .Select(t => new { Type = t, HandlerInterfaces = t.GetInterfaces().Where(IsHandler) }) .Where(a => a.HandlerInterfaces.Any()) .Where(a => predicate(a.Type)) .SelectMany(a => a.HandlerInterfaces .Select(i => new { Service = i, Implementation = a.Type, })); foreach (var handler in messageHandlers) { log.Debug("Registering handler {0} -> {1}", handler.Implementation, handler.Service); containerAdapter.Register(handler.Implementation, Lifestyle.Instance, handler.Service); } }
/// <summary> /// Configures <see cref="UnitOfWorkScope"/> settings. /// </summary> /// <param name="containerAdapter">The <see cref="IContainerAdapter"/> instance.</param> public void Configure(IContainerAdapter containerAdapter) { containerAdapter.Register<ITransactionManager, TransactionManager>(); UnitOfWorkSettings.AutoCompleteScope = _autoCompleteScope; UnitOfWorkSettings.DefaultIsolation = _defaultIsolation; }
/// <summary> /// Registers default components for NCommon. /// </summary> void InitializeDefaults() { _containerAdapter.Register <IContext, Context.Impl.Context>(); }
public void RegisterComponents(IContainerAdapter containerAdapter) { containerAdapter.Register<IDependantClass, DependantClass>(); containerAdapter.Register<IDependantClass, DependantClass2>("new name"); }
/// <summary> /// Initializes a new instance of the <see cref="ContextMapper{TContext}"/> class. /// </summary> /// <param name="container">The container.</param> /// <param name="contextProvider">The context provider.</param> public ContextMapper(IContainerAdapter container, IContextProvider <TContext> contextProvider) : this(container) { container.Register <IContextProvider <TContext> >(() => new TracingContextProviderDecorator <TContext>(contextProvider)); }
public void RegisterComponents(IContainerAdapter containerAdapter) { containerAdapter.Register <IDependantClass, DependantClass>(); containerAdapter.Register <IDependantClass, DependantClass2>("new name"); }
/// <summary> /// Configures <see cref="UnitOfWorkScope"/> settings. /// </summary> /// <param name="containerAdapter">The <see cref="IContainerAdapter"/> instance.</param> public void Configure(IContainerAdapter containerAdapter) { containerAdapter.Register <ITransactionManager, TransactionManager>(); UnitOfWorkSettings.AutoCompleteScope = _autoCompleteScope; UnitOfWorkSettings.DefaultIsolation = _defaultIsolation; }
public void Register(IEnumerable <IBrick> bricks) { var mergedDependencies = bricks.SelectMany(b => b.Dependencies); _containerAdapter.Register(mergedDependencies); }