示例#1
0
        private void organize(ServiceRegistry services)
        {
            DecoratorPolicies = services.FindAndRemovePolicies <IDecoratorPolicy>();

            FamilyPolicies = services.FindAndRemovePolicies <IFamilyPolicy>()
                             .Concat(new IFamilyPolicy[]
            {
                new EnumerablePolicy(),
                new FuncOrLazyPolicy(),
                new CloseGenericFamilyPolicy(),
                new ConcreteFamilyPolicy(),
                new EmptyFamilyPolicy()
            })
                             .ToArray();


            setterPolicies   = services.FindAndRemovePolicies <ISetterPolicy>();
            InstancePolicies = services.FindAndRemovePolicies <IInstancePolicy>();

            var policies = services.FindAndRemovePolicies <IRegistrationPolicy>();

            foreach (var policy in policies)
            {
                policy.Apply(services);
            }


            services.Add(new ScopeInstance <Scope>());
            services.Add(new ScopeInstance <IServiceProvider>());
            services.Add(new ScopeInstance <IServiceContext>());

            services.Add(new ScopeInstance <IContainer>());;
            services.Add(new RootScopeInstance <IServiceScopeFactory>());;
        }
示例#2
0
            public ConstructorInstance Use(Type concreteType)
            {
                var instance = new ConstructorInstance(_serviceType, concreteType, ServiceLifetime.Transient);

                _parent.Add(instance);

                return(instance);
            }
示例#3
0
            public ConstructorInstance <TConcrete> Use <TConcrete>() where TConcrete : class, T
            {
                var instance = ConstructorInstance.For <T, TConcrete>();

                instance.Lifetime = _lifetime;

                _parent.Add(instance);

                return(instance);
            }
示例#4
0
            public ConstructorInstance <TConcrete, T> Use <TConcrete>() where TConcrete : class, T
            {
                var instance = ConstructorInstance.For <T, TConcrete>();

                if (_lifetime != null)
                {
                    instance.Lifetime = _lifetime.Value;
                }

                _parent.Add(instance);

                return(instance);
            }
示例#5
0
        private void organize(ServiceRegistry services)
        {
            DecoratorPolicies = services.FindAndRemovePolicies <IDecoratorPolicy>();

            FamilyPolicies = services.FindAndRemovePolicies <IFamilyPolicy>()
                             .Concat(new IFamilyPolicy[]
            {
                new EnumerablePolicy(),
                new FuncOrLazyPolicy(),
                new CloseGenericFamilyPolicy(),
                new ConcreteFamilyPolicy(),
                new EmptyFamilyPolicy()
            })
                             .ToArray();


            setterPolicies   = services.FindAndRemovePolicies <ISetterPolicy>();
            InstancePolicies = services.FindAndRemovePolicies <IInstancePolicy>();

            var policies = services.FindAndRemovePolicies <IRegistrationPolicy>();

            foreach (var policy in policies)
            {
                policy.Apply(services);
            }

            var sets = services.FindAndRemovePolicies <CachedResolverSet>();

            foreach (var resolverSet in sets)
            {
                if (resolverSet.TryLoadResolvers(out var dict))
                {
                    foreach (var pair in dict)
                    {
                        CachedResolverTypes.Add(pair.Key, pair.Value);
                    }
                }
            }

            services.Add(new ScopeInstance <Scope>());
            services.Add(new ScopeInstance <IServiceProvider>());
            services.Add(new ScopeInstance <IServiceContext>());

            services.Add(new ScopeInstance <IContainer>());;
            services.Add(new RootScopeInstance <IServiceScopeFactory>());;
        }