Exemple #1
0
        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));
        }
Exemple #2
0
        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.
");
                }
            }
        }
Exemple #3
0
        public void RegisterComponents(IMongoClient client)
        {
            RegisterDefaults();

            _containerAdapter.RegisterInstance <IMongoClient>(client);

            _containerAdapter.Register <IMigrationService, MigrationService>();
        }
Exemple #4
0
        IBus CreateBus(string serviceName, IContainerAdapter containerAdapter)
        {
            var sagaCollectionName          = serviceName + ".sagas";
            var subscriptionsCollectionName = "rebus.subscriptions";

            DropCollection(sagaCollectionName);
            DropCollection(subscriptionsCollectionName);

            var inputQueueName = GetEndpoint(serviceName);

            var queue = messageQueueFactory.GetQueue(inputQueueName);

            var sagaPersister = new MongoDbSagaPersister(ConnectionString)
                                .SetCollectionName <CheckCreditSagaData>("check_credit_sagas")
                                .SetCollectionName <CheckSomeLegalStuffSagaData>("check_legal_sagas")
                                .SetCollectionName <CustomerInformationSagaData>("customer_information_sagas");

            var bus = new RebusBus(containerAdapter, queue.Item1, queue.Item2,
                                   new MongoDbSubscriptionStorage(ConnectionString, subscriptionsCollectionName),
                                   sagaPersister, this,
                                   new JsonMessageSerializer(), new TrivialPipelineInspector(),
                                   new ErrorTracker("error"));

            stuffToDispose.Add(bus);

            containerAdapter.RegisterInstance(bus, typeof(IBus));

            return(bus.Start(5));
        }
        public void PrebuiltInstance(IContainerAdapter adapter)
        {
            var instance = new IndependentService();
            adapter.RegisterInstance<IService>(instance);

            var resolved = adapter.Resolve<IService>();

            Assert.Same(instance, resolved);
        }
        //public UnityEFConfiguration WithObjectContextAndLogger(Func<ObjectContext> objectContextProvider, Func<ILoggingAdapter> loggingProvider)
        //{
        //    Guard.Against<ArgumentNullException>(objectContextProvider == null,
        //                                         "Expected a non-null Func<ObjectContext> instance.");
        //    Guard.Against<ArgumentNullException>(loggingProvider == null,
        //                                         "Expected a non-null Func<ILoggingAdapter> instance.");
        //    _factory.RegisterObjectContextProvider(objectContextProvider, loggingProvider);
        //    return this;
        //}

        //public UnityEFConfiguration WithLoggerProvider(Func<DbContext, ILoggingAdapter> loggerProvider)
        //{
        //    this.loggerProvider = loggerProvider;
        //    return this;
        //}

        /// <summary>
        /// Called by NCommon <see cref="Configure"/> to configure data providers.
        /// </summary>
        /// <param name="containerAdapter">The <see cref="IContainerAdapter"/> instance that allows
        /// registering components.</param>
        public void Configure(IContainerAdapter containerAdapter)
        {
            //Guard.Against<NotSupportedException>(loggerProvider==null, "Ошибка установки конфигурации EF: не определен логгер");
            //Guard.Against<NotSupportedException>(!(objectContextProvider() is ILoggerDataContext<DbContext>), "Ошибка установки конфигурации EF: дата контекст не поддерживает ILoggerDataContext");

            //(objectContextProvider() as ILoggerDataContext<DbContext>).LoggerProvider = loggerProvider;
            containerAdapter.RegisterInstance <IUnitOfWorkFactory>(_factory);
            containerAdapter.RegisterGeneric(typeof(IRepository <>), typeof(UnityEFRepository <>));
        }
Exemple #7
0
        public void PrebuiltInstance(IContainerAdapter adapter)
        {
            var instance = new IndependentService();

            adapter.RegisterInstance <IService>(instance);

            var resolved = adapter.Resolve <IService>();

            Assert.Same(instance, resolved);
        }
        public ApplicationController(IContainerAdapter container)
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }

            _container = container;
            _container.RegisterInstance <IApplicationController>(this);
        }
        public void ConstructorDependencyUsingInstance(IContainerAdapter adapter)
        {
            var instance = new IndependentService();
            adapter.RegisterInstance<IService>(instance);
            adapter.RegisterType<ServiceWithSimpleConstructorDependency>();

            var dependent = adapter.Resolve<ServiceWithSimpleConstructorDependency>();

            Assert.Same(instance, dependent.Service);
        }
        /// <summary>
        /// Called by NCommon <see cref="Configure"/> to configure data providers.
        /// </summary>
        /// <param name="containerAdapter">The <see cref="IContainerAdapter"/> instance that allows
        /// registering components.</param>
        public void Configure(IContainerAdapter containerAdapter)
        {
//#if DEBUG
            using (MiniProfiler.Current.Step("EFConfiguration.Configure")) {
//#endif
                containerAdapter.RegisterInstance <IUnitOfWorkFactory>(_factory);
                containerAdapter.RegisterGeneric(typeof(IRepository <>), typeof(EFRepository <>));
//#if DEBUG
            }
//#endif
        }
 /// <summary>
 /// Called by NCommon <see cref="Configure"/> to configure data providers.
 /// </summary>
 /// <param name="containerAdapter">The <see cref="IContainerAdapter"/> instance that allows
 /// registering components.</param>
 public void Configure(IContainerAdapter containerAdapter)
 {
     //#if DEBUG
     using (MiniProfiler.Current.Step("EFConfiguration.Configure")) {
     //#endif
         containerAdapter.RegisterInstance<IUnitOfWorkFactory>(_factory);
         containerAdapter.RegisterGeneric(typeof(IRepository<>), typeof(EFRepository<>));
     //#if DEBUG
     }
     //#endif
 }
Exemple #12
0
        public void ConstructorDependencyUsingInstance(IContainerAdapter adapter)
        {
            var instance = new IndependentService();

            adapter.RegisterInstance <IService>(instance);
            adapter.RegisterType <ServiceWithSimpleConstructorDependency>();

            var dependent = adapter.Resolve <ServiceWithSimpleConstructorDependency>();

            Assert.Same(instance, dependent.Service);
        }
        //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()));
        }
Exemple #14
0
 public static void RegisterInstance(this IContainerAdapter container, object instance)
 {
     container.RegisterInstance(instance.GetType(), instance);
 }
Exemple #15
0
 public static void RegisterInstance <TService>(this IContainerAdapter container, TService instance)
 {
     container.RegisterInstance(typeof(TService), instance);
 }
 public RebusConfigurerWithLogging(IContainerAdapter containerAdapter)
     : base(containerAdapter)
 {
     containerAdapter.RegisterInstance(containerAdapter, typeof(IActivateHandlers));
 }
 public IApplicationController RegisterInstance <TImplementation>(TImplementation instance) where TImplementation : class
 {
     _container.RegisterInstance(instance);
     return(this);
 }
Exemple #18
0
 public void Use <T>(T instance) where T : IStoreSagaData
 {
     containerAdapter.RegisterInstance(instance, typeof(IStoreSagaData));
 }
Exemple #19
0
 public RebusConfigurerWithLogging(IContainerAdapter containerAdapter) : base(containerAdapter)
 {
     containerAdapter.RegisterInstance(containerAdapter, typeof(IActivateHandlers));
 }
 public void Use <T>(T instance) where T : IInspectHandlerPipeline
 {
     containerAdapter.RegisterInstance(instance, typeof(IInspectHandlerPipeline));
 }
 public void Use <T>(T instance) where T : ISerializeMessages
 {
     containerAdapter.RegisterInstance(instance, typeof(ISerializeMessages));
 }
Exemple #22
0
 public void Use <T>(T instance) where T : IStoreSubscriptions
 {
     containerAdapter.RegisterInstance(instance, typeof(IStoreSubscriptions));
 }
Exemple #23
0
 public RebusConfigurer(IContainerAdapter containerAdapter)
 {
     this.containerAdapter = containerAdapter;
     containerAdapter.RegisterInstance(containerAdapter, typeof (IActivateHandlers));
 }
Exemple #24
0
 /// <summary>
 /// Called by Kt.Framework.Repository <see cref="Configure"/> to configure data providers.
 /// </summary>
 /// <param name="containerAdapter">The <see cref="IContainerAdapter"/> instance that allows
 /// registering components.</param>
 public void Configure(IContainerAdapter containerAdapter)
 {
     containerAdapter.RegisterInstance<IUnitOfWorkFactory>(_factory);
     containerAdapter.RegisterGeneric(typeof(IRepository<>), typeof(EFRepository<>));
 }
 /// <summary>
 /// Makes the configurer insert the provided <see cref="IDetermineDestination"/> instance
 /// into the container adapter.
 /// </summary>
 public void Use <T>(T instance) where T : IDetermineDestination
 {
     containerAdapter.RegisterInstance(instance, typeof(IDetermineDestination));
 }