public ToposConsumerConfigurer(Action <StandardConfigurer <IConsumerImplementation> > configure, string groupName)
        {
            var configurer = StandardConfigurer <IConsumerImplementation> .New(_injectionist);

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

            configure(configurer);
        }
Example #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");
 }
Example #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);
 }
Example #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());
        }
Example #5
0
        internal RebusConfigurer(IHandlerActivator handlerActivator)
        {
            _injectionist.Register(c => handlerActivator);

            if (handlerActivator is IContainerAdapter)
            {
                _injectionist.Register(c => (IContainerAdapter)handlerActivator);
            }
        }
Example #6
0
        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);
            }
        }
        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",
            }));
        }
Example #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",
            }));
        }
        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);
        }
Example #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;
        }
Example #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);
 }
Example #12
0
        void InstallDefaults()
        {
            _logger.Verbose("Installing defaults");

            if (!_injectionist.Has <INanosInstance>())
            {
                _injectionist.Register <INanosInstance>(c => new DefaultNanosInstance());
            }
        }
        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));
        }
Example #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);
    }
Example #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);
 }
Example #16
0
 public IConfigDriveBuilder With <T>(T instance) where T : class
 {
     _container.Register(c => instance);
     return(this);
 }
Example #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);
 }
Example #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);
 }
Example #19
0
 /// <summary>
 /// Configures this Rebus instance to use the specified logger factory
 /// </summary>
 public void Use(IRebusLoggerFactory rebusLoggerFactory)
 {
     _injectionist.Register(c => rebusLoggerFactory);
 }
Example #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);
 }
Example #21
0
 public Registrar <TService> Register(Func <IResolutionContext, TService> resolverMethod, string description = null)
 {
     _injectionist.Register(resolverMethod, description);
     return(this);
 }