public IToposProducer Create()
        {
            ToposConfigurerHelpers.RegisterCommonServices(_injectionist);

            _injectionist.PossiblyRegisterDefault <ITopicMapper>(c => new SimpleTopicMapper());

            _injectionist.Register <IToposProducer>(c =>
            {
                var messageSerializer      = c.Get <IMessageSerializer>();
                var topicMapper            = c.Get <ITopicMapper>();
                var producerImplementation = c.Get <IProducerImplementation>(errorMessage: "Røvhul");
                var loggerFactory          = c.Get <ILoggerFactory>();

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

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

                return(defaultToposProducer);
            });

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

            return(resolutionResult.Instance);
        }
Esempio n. 2
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);
    }