Exemple #1
0
        public override IComponentRegistry Register(Type dependencyType, Type implementationType, Lifestyle lifestyle)
        {
            Guard.AgainstNull(dependencyType, "dependencyType");
            Guard.AgainstNull(implementationType, "implementationType");

            base.Register(dependencyType, implementationType, lifestyle);

            try
            {
                switch (lifestyle)
                {
                case Lifestyle.Transient:
                {
                    _container.Register(dependencyType, implementationType, global::SimpleInjector.Lifestyle.Transient);

                    break;
                }

                default:
                {
                    _container.Register(dependencyType, implementationType, global::SimpleInjector.Lifestyle.Singleton);

                    break;
                }
                }
            }
            catch (Exception ex)
            {
                throw new TypeRegistrationException(ex.Message, ex);
            }

            return(this);
        }
Exemple #2
0
        public Container Resolver()
        {
            GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.NullValueHandling = NullValueHandling.Include;

            _container.Register <IServicoAplicacaoVeiculo, ServicoAplicacaoVeiculo>();
            _container.Register <IServicoVeiculo, ServicoVeiculo>();
            _container.Register <IRepositorioVeiculo, RepositorioVeiculo>();

            _container.Verify();
            return(_container);
        }
        public void RegisterServices(global::SimpleInjector.Container container)
        {
            container.Register <ISitecoreContext>(() => new SitecoreContext());
            container.Register <IMetadataLogic, MetadataLogic>();
            container.Register <IScriptsLogic, ScriptsLogic>();
            container.Register <ISitecoreSiteLogic, SitecoreSiteLogic>();
            container.Register <IDateTimeLogic, DateTimeLogic>();
            container.Register <ICanonicalLink, CanonicalLink>();
            container.Register <ISettingsLogic, SettingsLogic>();



            container.Register <ICacheLogic, CacheLogic>();
            //singleton
            container.Register <ICacheRepositoryLogic, CacheRepositoryLogic>(Lifestyle.Singleton);
        }
Exemple #4
0
        public RabbitMQIntegrationModule(global::SimpleInjector.Container container)
        {
            container.Register <IRabbitBus, RabbitBus>(SimpleInjector.Lifestyle.Transient);

            var handler = DefineBusHandler();

            IBus bus = RabbitHutch.CreateBus(ConfigHelper.ConnectionString, handler, serviceRegister => serviceRegister
                                             .Register <IEasyNetQLogger, QueueLogManager>()
                                             .Register <IConsumerErrorStrategy, ErrorStrategy>());

            container.RegisterSingle <IBus>(bus);

            this.container = container;
        }
            public Endpoint()
            {
                var container = new global::SimpleInjector.Container();

                container.Options.AllowOverridingRegistrations = true;
                container.Options.DefaultScopedLifestyle       = new AsyncScopedLifestyle();
                container.Options.AutoWirePropertiesImplicitly();

                container.Register(() => new MyService {
                    Id = "Created outside"
                }, global::SimpleInjector.Lifestyle.Scoped);

                EndpointSetup <DefaultServer>(config =>
                {
                    config.UseContainer <SimpleInjectorBuilder>(customization =>
                    {
                        customization.UseExistingContainer(container);
                    });
                    config.SendFailedMessagesTo("error");
                });
            }
        /// <summary>
        /// Register a binding of a type to a callback that can resolve an instance of the type with a given lifecycle
        /// </summary>
        /// <param name="container"><see cref="global::SimpleInjector.Container"/> to register into</param>
        /// <param name="service"><see cref="Type"/> to register</param>
        /// <param name="resolveCallback"><see cref="Func{T}"/> that resolves the instance</param>
        /// <param name="lifecycle"><see cref="BindingLifecycle">Lifecycle</see> of the binding</param>
        public static void Register(this global::SimpleInjector.Container container, Type service, Func <Type, object> resolveCallback, BindingLifecycle lifecycle)
        {
            var lifestyle = ResolveLifestyle(lifecycle);

            container.Register(service, () => resolveCallback, lifestyle);
        }
 /// <summary>
 /// Register a binding of a type to a callback that can resolve it with a given lifecycle
 /// </summary>
 /// <typeparam name="T">Type to register</typeparam>
 /// <param name="container"><see cref="global::SimpleInjector.Container"/> to register into</param>
 /// <param name="resolveCallback"><see cref="Func{T}"/> that resolves the type</param>
 /// <param name="lifecycle"><see cref="BindingLifecycle">Lifecycle</see> of the binding</param>
 public static void Register <T>(this global::SimpleInjector.Container container, Func <Type> resolveCallback, BindingLifecycle lifecycle)
 {
     container.Register(typeof(T), resolveCallback, lifecycle);
 }
        /// <summary>
        /// Register a binding of a type to a callback that can resolve an instance of the type with a given lifecycle
        /// </summary>
        /// <typeparam name="T">Type to register</typeparam>
        /// <param name="container"><see cref="global::SimpleInjector.Container"/> to register into</param>
        /// <param name="resolveCallback"><see cref="Func{T}"/> that resolves the type by returning an instance</param>
        /// <param name="lifecycle"><see cref="BindingLifecycle">Lifecycle</see> of the binding</param>
        public static void Register <T>(this global::SimpleInjector.Container container, Func <T> resolveCallback, BindingLifecycle lifecycle)
        {
            Func <Type> typeResolver = () => { return(resolveCallback.Invoke().GetType()); };

            container.Register(typeof(T), typeResolver, lifecycle);
        }
Exemple #9
0
 public void Bind(Type service, Func <Type> resolveCallback)
 {
     _container.Register(service, resolveCallback);
 }
Exemple #10
0
 /// <inheritdoc/>
 public void Bind(Type service, Func <Type> resolveCallback)
 {
     _container.Register(service, resolveCallback, DefaultLifecycle);
 }
Exemple #11
0
        static void Test()
        {
            var dry = new DryIoc.Container();

            dry.Register <IMetricSubmitter, EnrichMetricsDecorator>(
                setup: new DecoratorSetup(z =>
            {
                return(z.Parent.ImplementationType == typeof(SingleWorker));
            }, order: 0, useDecorateeReuse: false));
            dry.Register <IMetricSubmitter, DefaultMetricSubmitter>(Reuse.Singleton);
            dry.Register <SingleWorker>(Reuse.Singleton);
            dry.Register <ScopedWorker>(Reuse.Singleton);
            var worker = dry.Resolve <SingleWorker>();

            Console.WriteLine(worker);
            var worker2 = dry.Resolve <ScopedWorker>();

            Console.WriteLine(worker2);


            var container = new global::SimpleInjector.Container();

            container.Options.DefaultScopedLifestyle = new AsyncScopedLifestyle();

            container.ForConsumer <BConsumer>()
            .RegisterSingleton <AInterface, BImplementation>();

            container.ForConsumer <AConsumer>()
            .Register <AInterface, AImplementation>(Lifestyle.Singleton);

            container.RegisterSingleton <AConsumer>();

            container.RegisterDecorator(
                typeof(AInterface), typeof(AInterfaceDecorator), Lifestyle.Singleton,
                z =>
            {
                return(true);
            });
            container.RegisterDecorator(
                typeof(AInterface), typeof(BInterfaceDecorator), Lifestyle.Singleton,
                z =>
            {
                return(true);
            });


            container.Register <SingleWorker>(Lifestyle.Singleton);
            container.Register <ScopedWorker>(Lifestyle.Scoped);

            container.RegisterDecorator <IMetricSubmitter, EnrichMetricsDecorator>();
            container.RegisterConditional <IMetricSubmitter, ProxyMetricSubmitter>(
                Lifestyle.Singleton,
                z => z.Consumer.ImplementationType == typeof(SingleWorker));



            container.Verify();

            container.GetInstance <SingleWorker>();
            using (AsyncScopedLifestyle.BeginScope(container))
            {
                container.GetInstance <ScopedWorker>();
            }

            container.GetInstance <AConsumer>();
            container.GetInstance <AConsumer>();
            container.GetInstance <BConsumer>();
            container.GetInstance <BConsumer>();
        }