コード例 #1
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);
        }
コード例 #2
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>();
        }