private object DoBuildUp(Type t, object existing, string name, InjectionMember[] injectionMembers)
        {
            var transientPolicies = new PolicyList(this.Context.Policies);
            foreach (var member in injectionMembers)
            {
                member.AddPolicies(null, t, name, transientPolicies);
            }

            object result;
            var buildContext = new BuilderContext(Context.Strategies.MakeStrategyChain(),
                Context.Lifetime, Context.Policies, transientPolicies, new NamedTypeBuildKey(t, name),
                existing);
            try
            {
                result = buildContext.Strategies.ExecuteBuildUp(buildContext);
            }
            catch (Exception exception)
            {
                throw new ResolutionFailedException(t, name, exception, buildContext);
            }
            return result;
        }
Exemplo n.º 2
0
        private void InitializeBuilderState()
        {
            registeredNames = new NamedTypesRegistry(ParentNameRegistry);
            extensions = new List<UnityContainerExtension>();

            locator = new Locator(ParentLocator);
            lifetimeContainer = new LifetimeContainer();
            strategies = new StagedStrategyChain<UnityBuildStage>(ParentStrategies);
            buildPlanStrategies = new StagedStrategyChain<UnityBuildStage>(ParentBuildPlanStrategies);
            policies = new PolicyList(ParentPolicies);

            cachedStrategies = null;
            cachedStrategiesLock = new object();
        }
Exemplo n.º 3
0
 private BuilderContext GetContext(IUnityContainer container, NamedTypeBuildKey buildKey)
 {
     StrategyChain strategies = new StrategyChain();
     strategies.Add(new ReturnContainerStrategy(container));
     PolicyList persistentPolicies = new PolicyList();
     PolicyList transientPolicies = new PolicyList(persistentPolicies);
     return new BuilderContext(strategies, null, persistentPolicies, transientPolicies, buildKey, null);
 }
		private PolicyList CreatePolicyList(ConfigurationSection settings, bool applyInjectionPolicies)
        {
            DictionaryConfigurationSource configurationSource = new DictionaryConfigurationSource();
            configurationSource.Add(PolicyInjectionSettings.SectionName, settings);

			PolicyList policyList = new PolicyList();
			policyList.SetDefault<IPolicyInjectionPolicy>(new PolicyInjectionPolicy(applyInjectionPolicies));
            //policyList.Set<IPolicyInjectionPolicy>(new PolicyInjectionPolicy(false),
            //                                       typeof(ClassThatDependsOnIInterface));
			policyList.Set<IConfigurationObjectPolicy>(new ConfigurationObjectPolicy(configurationSource),
													   typeof(IConfigurationSource));

            policyList.SetDefault<IBuildPlanCreatorPolicy>(new DynamicMethodBuildPlanCreatorPolicy(buildPlanStrategyChain));
		    policyList.SetDefault<IDynamicBuilderMethodCreatorPolicy>(new DefaultDynamicBuilderMethodCreatorPolicy());
            policyList.SetDefault<IConstructorSelectorPolicy>(new ConstructorSelectorPolicy<Attribute>());
            policyList.SetDefault<IPropertySelectorPolicy>(new PropertySelectorPolicy<Attribute>());

			return policyList;
        }