Ejemplo n.º 1
0
        protected override void Setup(FeatureConfigurationContext context)
        {
            var settings  = context.Settings;
            var container = Configuration.Settings.Container;


            context.Container.ConfigureComponent <IDomainUnitOfWork>((c) => new NSBUnitOfWork(c.Build <IRepositoryFactory>(), c.Build <IEventFactory>(), c.Build <IProcessor>()), DependencyLifecycle.InstancePerUnitOfWork);
            context.Container.ConfigureComponent <IEventFactory>((c) => new EventFactory(c.Build <IMessageCreator>()), DependencyLifecycle.InstancePerCall);
            context.Container.ConfigureComponent <IMessageDispatcher>((c) => new Dispatcher(c.Build <IMetrics>(), c.Build <IMessageSerializer>(), c.Build <IEventMapper>()), DependencyLifecycle.InstancePerCall);
            context.Container.ConfigureComponent <IMessaging>((c) => new NServiceBusMessaging(c.Build <MessageHandlerRegistry>(), c.Build <MessageMetadataRegistry>()), DependencyLifecycle.InstancePerCall);

            context.Container.ConfigureComponent <IEventMapper>((c) => new EventMapper(c.Build <IMessageMapper>()), DependencyLifecycle.SingleInstance);

            if (!Configuration.Settings.Passive)
            {
                //container.Register<IDomainUnitOfWork, NSBUnitOfWork>();
                MutationManager.RegisterMutator("domain unit of work", typeof(IDomainUnitOfWork));

                context.Pipeline.Register(
                    b => new ExceptionRejector(b.Build <IMetrics>(), Configuration.Settings.Retries),
                    "Watches message faults, sends error replies to client when message moves to error queue"
                    );

                context.Pipeline.Register <UowRegistration>();
                context.Pipeline.Register <CommandAcceptorRegistration>();
                context.Pipeline.Register <LocalMessageUnpackRegistration>();
                // Remove NSBs unit of work since we do it ourselves
                context.Pipeline.Remove("ExecuteUnitOfWork");

                // bulk invoke only possible with consumer feature because it uses the eventstore as a sink when overloaded
                context.Pipeline.Replace("InvokeHandlers", (b) =>
                                         new BulkInvokeHandlerTerminator(container.Resolve <IMetrics>(), b.Build <IEventMapper>()),
                                         "Replaces default invoke handlers with one that supports our custom delayed invoker");
            }


            if (Configuration.Settings.SlowAlertThreshold.HasValue)
            {
                context.Pipeline.Register(
                    behavior: new TimeExecutionBehavior(Configuration.Settings.SlowAlertThreshold.Value),
                    description: "times the execution of messages and reports anytime they are slow"
                    );
            }

            var types = settings.GetAvailableTypes();

            // Register all query handlers in my IoC so query processor can use them
            foreach (var type in types.Where(IsQueryHandler))
            {
                container.Register(type, Lifestyle.PerInstance);
            }

            context.Pipeline.Register <MutateIncomingRegistration>();
            context.Pipeline.Register <MutateOutgoingRegistration>();

            // We are sending IEvents, which NSB doesn't like out of the box - so turn that check off
            context.Pipeline.Remove("EnforceSendBestPractices");

            context.RegisterStartupTask(builder => new EndpointRunner(context.Settings.InstanceSpecificQueue(), Configuration.Settings, Configuration.Settings.StartupTasks, Configuration.Settings.ShutdownTasks));
        }
Ejemplo n.º 2
0
        protected override void Setup(FeatureConfigurationContext context)
        {
            var settings  = context.Settings;
            var container = Configuration.Settings.Container;

            context.Pipeline.Register <ExceptionRejectorRegistration>();

            if (!Configuration.Settings.Passive)
            {
                MutationManager.RegisterMutator("domain unit of work", typeof(UnitOfWork.IDomain));


                context.Pipeline.Register <UowRegistration>();
                context.Pipeline.Register <CommandAcceptorRegistration>();
                context.Pipeline.Register <SagaBehaviourRegistration>();

                // Remove NSBs unit of work since we do it ourselves
                context.Pipeline.Remove("ExecuteUnitOfWork");

                // bulk invoke only possible with consumer feature because it uses the eventstore as a sink when overloaded
                context.Pipeline.Replace("InvokeHandlers", (b) =>
                                         new BulkInvokeHandlerTerminator(b.Build <IMetrics>(), b.Build <IEventMapper>()),
                                         "Replaces default invoke handlers with one that supports our custom delayed invoker");
            }

            context.Pipeline.Register <LocalMessageUnpackRegistration>();
            context.Pipeline.Register <LogContextProviderRegistration>();

            if (Configuration.Settings.SlowAlertThreshold.HasValue)
            {
                context.Pipeline.Register(
                    behavior: new TimeExecutionBehavior(),
                    description: "times the execution of messages and reports anytime they are slow"
                    );
            }

            var types = settings.GetAvailableTypes();

            var messageMetadataRegistry = settings.Get <MessageMetadataRegistry>();

            context.Pipeline.Register <MessageIdentifierRegistration>();
            context.Pipeline.Register <MessageDetyperRegistration>();

            // Register all service handlers in my IoC so query processor can use them
            foreach (var type in types.Where(IsServiceHandler))
            {
                container.Register(type, Lifestyle.PerInstance);
            }

            context.Pipeline.Register <MutateIncomingRegistration>();
            context.Pipeline.Register <MutateOutgoingRegistration>();

            // We are sending IEvents, which NSB doesn't like out of the box - so turn that check off
            context.Pipeline.Remove("EnforceSendBestPractices");

            context.RegisterStartupTask(builder => new EndpointRunner(context.Settings.InstanceSpecificQueue(), Configuration.Settings, Configuration.Settings.StartupTasks, Configuration.Settings.ShutdownTasks));
        }