コード例 #1
0
        public ToposConsumerConfigurer(Action <StandardConfigurer <IConsumerImplementation> > configure, string groupName)
        {
            var configurer = StandardConfigurer <IConsumerImplementation> .New(_injectionist);

            _injectionist.Register(c => new GroupId(groupName));

            configure(configurer);
        }
コード例 #2
0
 /// <summary>
 /// Configures this Rebus instance to use the specified logger factory
 /// </summary>
 public void Use(IRebusLoggerFactory rebusLoggerFactory)
 {
     if (rebusLoggerFactory == null)
     {
         throw new ArgumentNullException(nameof(rebusLoggerFactory));
     }
     _injectionist.Register(c => rebusLoggerFactory, $"This Rebus instance has been configured to use the {rebusLoggerFactory} logger factory");
 }
コード例 #3
0
 /// <summary>
 /// Configures this Rebus instance to use the specified logger factory
 /// </summary>
 public void Use(IRebusLoggerFactory rebusLoggerFactory)
 {
     if (rebusLoggerFactory == null)
     {
         throw new ArgumentNullException(nameof(rebusLoggerFactory));
     }
     _injectionist.Register(c => rebusLoggerFactory);
 }
コード例 #4
0
        public ConfigDriveBuilder(Injectionist container)
        {
            _container = container;
            _container.Register <IConfigDrive>(ctx => new ConfigDrive(
                                                   ctx.Get <IConfigDriveDataSource>()));

            _container.Register <IYamlSerializer>(ctx => new YamlSerializer());
            _container.Register <IUserDataSerializer>(ctx => new UserDataSerializer());
        }
コード例 #5
0
ファイル: RebusConfigurer.cs プロジェクト: mhertis/Rebus
        internal RebusConfigurer(IHandlerActivator handlerActivator)
        {
            _injectionist.Register(c => handlerActivator);

            if (handlerActivator is IContainerAdapter)
            {
                _injectionist.Register(c => (IContainerAdapter)handlerActivator);
            }
        }
コード例 #6
0
ファイル: RebusConfigurer.cs プロジェクト: crazyants/Rebus
        internal RebusConfigurer(IHandlerActivator handlerActivator)
        {
            if (handlerActivator == null)
            {
                throw new ArgumentNullException(nameof(handlerActivator));
            }

            _injectionist.Register(c => handlerActivator);

            if (handlerActivator is IContainerAdapter)
            {
                _injectionist.Register(c => (IContainerAdapter)handlerActivator);
            }
        }
コード例 #7
0
        public void InjectedWhateverWithWhateverInsideIsProperlyDisposed()
        {
            var injectionist = new Injectionist();
            var eventTracker = new EventTracker();

            injectionist.Register(c =>
            {
                var fakeBus = new FakeBus(c.Get<Disposable1>(), c.Get<EventTracker>());

                fakeBus.FakeBusDisposed += () =>
                {
                    foreach (var disposable in c.GetTrackedInstancesOf<IDisposable>().Reverse())
                    {
                        disposable.Dispose();
                    }
                };

                foreach (var disposable in c.GetTrackedInstancesOf<IInitializable>())
                {
                    disposable.Initialize();
                }

                return fakeBus;
            });
            injectionist.Register(c => new Disposable1(c.Get<Disposable2>(), c.Get<EventTracker>()));
            injectionist.Register(c => new Disposable2(c.Get<EventTracker>()));
            injectionist.Register(c => eventTracker);

            using (var bus = injectionist.Get<FakeBus>())
            {
                Console.WriteLine("Using the bus....");

                Console.WriteLine("Disposing it");
            }

            Console.WriteLine(@"Here's what happened:
{0}", string.Join(Environment.NewLine, eventTracker.Events.Select(e => "- " + e)));

            Assert.That(eventTracker.Events, Is.EqualTo(new[]
            {
                "EventTracker initialized",
                "Disposable2 initialized",
                "Disposable1 initialized",
                "Disposable1 disposed",
                "Disposable2 disposed",
                "EventTracker disposed",
                "FakeBus disposed",
            }));
        }
コード例 #8
0
        public void InjectedWhateverWithWhateverInsideIsProperlyDisposed()
        {
            var injectionist = new Injectionist();
            var eventTracker = new EventTracker();

            injectionist.Register(c =>
            {
                var fakeBus = new FakeBus(c.Get <Disposable1>(), c.Get <EventTracker>());

                fakeBus.FakeBusDisposed += () =>
                {
                    foreach (var disposable in c.GetTrackedInstancesOf <IDisposable>().Reverse())
                    {
                        disposable.Dispose();
                    }
                };

                foreach (var disposable in c.GetTrackedInstancesOf <IInitializable>())
                {
                    disposable.Initialize();
                }

                return(fakeBus);
            });
            injectionist.Register(c => new Disposable1(c.Get <Disposable2>(), c.Get <EventTracker>()));
            injectionist.Register(c => new Disposable2(c.Get <EventTracker>()));
            injectionist.Register(c => eventTracker);

            using (var bus = injectionist.Get <FakeBus>())
            {
                Console.WriteLine("Using the bus....");

                Console.WriteLine("Disposing it");
            }

            Console.WriteLine(@"Here's what happened:
{0}", string.Join(Environment.NewLine, eventTracker.Events.Select(e => "- " + e)));

            Assert.That(eventTracker.Events, Is.EqualTo(new[]
            {
                "EventTracker initialized",
                "Disposable2 initialized",
                "Disposable1 initialized",
                "Disposable1 disposed",
                "Disposable2 disposed",
                "EventTracker disposed",
                "FakeBus disposed",
            }));
        }
コード例 #9
0
        public ToposProducerConfigurer Topics(Action <TopicMapper> mapper)
        {
            if (mapper == null)
            {
                throw new ArgumentNullException(nameof(mapper));
            }

            if (!_injectionist.Has <ITopicMapper>())
            {
                _injectionist.Register(c => _topicMappings.BuildTopicMapper());
            }

            mapper(new TopicMapper(_topicMappings));
            return(this);
        }
コード例 #10
0
        /// <summary>
        /// Configures Rebus to use another endpoint as the timeout manager
        /// </summary>
        public void UseExternalTimeoutManager(string timeoutManagerAddress)
        {
            if (string.IsNullOrWhiteSpace(timeoutManagerAddress))
            {
                throw new ArgumentException($"Cannot use '{timeoutManagerAddress}' as an external timeout manager address!", nameof(timeoutManagerAddress));
            }

            if (!string.IsNullOrWhiteSpace(_options.ExternalTimeoutManagerAddressOrNull))
            {
                throw new InvalidOperationException(
                          $"Cannot set external timeout manager address to '{timeoutManagerAddress}' because it has already been set to '{_options.ExternalTimeoutManagerAddressOrNull}' - please set it only once!  (this operation COULD have been accepted, but it is probably an indication of an error in your configuration code that this value is configured twice, so we figured it was best to let you know)");
            }

            _injectionist.Register <ITimeoutManager>(c => new ThrowingTimeoutManager());
            _options.ExternalTimeoutManagerAddressOrNull = timeoutManagerAddress;
        }
コード例 #11
0
 /// <summary>
 /// Registers the given factory function as a resolve of the given <typeparamref name="TService"/> service
 /// </summary>
 public void Register(Func <IResolutionContext, TService> factoryMethod, string description = null)
 {
     if (factoryMethod == null)
     {
         throw new ArgumentNullException(nameof(factoryMethod));
     }
     _injectionist.Register(factoryMethod, description: description);
 }
コード例 #12
0
        void InstallDefaults()
        {
            _logger.Verbose("Installing defaults");

            if (!_injectionist.Has <INanosInstance>())
            {
                _injectionist.Register <INanosInstance>(c => new DefaultNanosInstance());
            }
        }
コード例 #13
0
        public static GeneratorBuilder Init()
        {
            var container = new Injectionist();

            container.Register <IConfigDriveGenerator>(
                c => new ConfigDriveGenerator(
                    c.Get <ICommandHandler <ProcessResultCommand> >(),
                    c.Get <ICommandHandler <GenerateResultCommand> >()));

            return(new GeneratorBuilder(container));
        }
コード例 #14
0
    public IToposProducer Create()
    {
        ToposConfigurerHelpers.RegisterCommonServices(_injectionist);

        _injectionist.Register <IToposProducer>(c =>
        {
            var messageSerializer      = c.Get <IMessageSerializer>();
            var producerImplementation = c.Get <IProducerImplementation>(errorMessage: "Failing to get the producer implementation can be caused by a missing registration of IProducerImplementation");
            var loggerFactory          = c.Get <ILoggerFactory>();

            var defaultToposProducer = new DefaultToposProducer(
                messageSerializer,
                producerImplementation,
                loggerFactory
                );

            defaultToposProducer.Disposing += () =>
            {
                foreach (var instance in c.TrackedInstances.OfType <IDisposable>().Reverse())
                {
                    instance.Dispose();
                }
            };

            return(defaultToposProducer);
        });

        var resolutionResult = _injectionist.Get <IToposProducer>();

        foreach (var initializable in resolutionResult.TrackedInstances.OfType <IInitializable>())
        {
            initializable.Initialize();
        }

        return(resolutionResult.Instance);
    }
コード例 #15
0
 /// <summary>
 /// Registers the given factory function as a resolve of the given <typeparamref name="TService"/> service
 /// </summary>
 public void Register(Func <IResolutionContext, TService> factoryMethod, string description = null)
 {
     _injectionist.Register(factoryMethod, description: description);
 }
コード例 #16
0
 public IConfigDriveBuilder With <T>(T instance) where T : class
 {
     _container.Register(c => instance);
     return(this);
 }
コード例 #17
0
 /// <summary>
 /// Registers the given factory function as a resolver of the given primary implementation of the <typeparamref name="TService"/> service
 /// </summary>
 public void Register <TService>(Func <IResolutionContext, TService> resolverMethod, string description = null)
 {
     _injectionist.Register(resolverMethod, description);
 }
コード例 #18
0
 /// <summary>
 /// Registers the given factory function as a resolve of the given <see cref="TService"/> service
 /// </summary>
 public void Register <TService>(Func <IResolutionContext, TService> resolverMethod)
 {
     _injectionist.Register(resolverMethod);
 }
コード例 #19
0
 /// <summary>
 /// Configures this Rebus instance to use the specified logger factory
 /// </summary>
 public void Use(IRebusLoggerFactory rebusLoggerFactory)
 {
     _injectionist.Register(c => rebusLoggerFactory);
 }
コード例 #20
0
 /// <summary>
 /// Registers the given factory function as a resolve of the given <typeparamref name="TService"/> service
 /// </summary>
 public void Register(Func <IResolutionContext, TService> factoryMethod)
 {
     _injectionist.Register(factoryMethod);
 }
コード例 #21
0
 public Registrar <TService> Register(Func <IResolutionContext, TService> resolverMethod, string description = null)
 {
     _injectionist.Register(resolverMethod, description);
     return(this);
 }