Esempio n. 1
0
        protected override void Initialize()
        {
            // Override base Unity policies.
            Context.Policies.ClearDefault <IConstructorSelectorPolicy>();
            Context.Policies.SetDefault <IConstructorSelectorPolicy>(
                new ContainerConstructorSelectorPolicy());
            Context.Policies.ClearDefault <IPropertySelectorPolicy>();
            Context.Policies.SetDefault <IPropertySelectorPolicy>(
                new ContainerPropertySelectorPolicy());

            // Set logging specific policies
            var buildKey = new NamedTypeBuildKey(typeof(ILogger));

            Context.Policies.Set <IParameterResolverPolicy>(
                new LoggerNameConstuctorParameterPolicy(), buildKey);
            Context.Policies.Set <IPropertyResolverPolicy>(
                new LoggerNamePropertyPolicy(), buildKey);
        }
        private static ILifetimePolicy GetLifetimePolicyForGenericType(IBuilderContext context)
        {
            Type   typeToBuild         = context.BuildKey.Type;
            object openGenericBuildKey = new NamedTypeBuildKey(typeToBuild.GetGenericTypeDefinition(),
                                                               context.BuildKey.Name);

            IPolicyList            factorySource;
            ILifetimeFactoryPolicy factoryPolicy =
                context.Policies.Get <ILifetimeFactoryPolicy>(openGenericBuildKey, out factorySource);

            if (factoryPolicy != null)
            {
                ILifetimePolicy lifetime = factoryPolicy.CreateLifetimePolicy();
                factorySource.Set <ILifetimePolicy>(lifetime, context.BuildKey);
                return(lifetime);
            }

            return(null);
        }
 /// <summary>
 /// Create a new <see cref="BuilderContext"/> using the explicitly provided
 /// values.
 /// </summary>
 /// <param name="chain">The <see cref="IStrategyChain"/> to use for this context.</param>
 /// <param name="lifetime">The <see cref="ILifetimeContainer"/> to use for this context.</param>
 /// <param name="persistentPolicies">The set of persistent policies to use for this context.</param>
 /// <param name="transientPolicies">The set of transient policies to use for this context. It is
 /// the caller's responsibility to ensure that the transient and persistent policies are properly
 /// combined.</param>
 /// <param name="buildKey">Build key for this context.</param>
 /// <param name="resolverOverrides">The resolver overrides.</param>
 protected BuilderContext(IStrategyChain chain, ILifetimeContainer lifetime, IPolicyList persistentPolicies, IPolicyList transientPolicies, NamedTypeBuildKey buildKey, CompositeResolverOverride resolverOverrides)
 {
     this.chain              = chain;
     this.lifetime           = lifetime;
     this.persistentPolicies = persistentPolicies;
     this.policies           = transientPolicies;
     this.originalBuildKey   = buildKey;
     this.BuildKey           = buildKey;
     this.Existing           = null;
     this.resolverOverrides  = resolverOverrides;
     this.ownsOverrides      = false;
 }
 /// <summary>
 /// Create a new <see cref="BuilderContext"/> using the explicitly provided
 /// values.
 /// </summary>
 /// <param name="chain">The <see cref="IStrategyChain"/> to use for this context.</param>
 /// <param name="lifetime">The <see cref="ILifetimeContainer"/> to use for this context.</param>
 /// <param name="persistentPolicies">The set of persistent policies to use for this context.</param>
 /// <param name="transientPolicies">The set of transient policies to use for this context. It is
 /// the caller's responsibility to ensure that the transient and persistent policies are properly
 /// combined.</param>
 /// <param name="buildKey">Build key for this context.</param>
 /// <param name="existing">Existing object to build up.</param>
 public BuilderContext(IStrategyChain chain, ILifetimeContainer lifetime, IPolicyList persistentPolicies, IPolicyList transientPolicies, NamedTypeBuildKey buildKey, object existing)
 {
     this.chain              = chain;
     this.lifetime           = lifetime;
     this.persistentPolicies = persistentPolicies;
     this.policies           = transientPolicies;
     this.originalBuildKey   = buildKey;
     this.BuildKey           = buildKey;
     this.Existing           = existing;
     this.resolverOverrides  = new CompositeResolverOverride();
     this.ownsOverrides      = true;
 }
 /// <summary>
 /// Create a new instance storing the given type.
 /// </summary>
 /// <param name="typeToBuild">Type to resolve.</param>
 public FixedTypeResolverPolicy(Type typeToBuild)
 {
     this.keyToBuild = new NamedTypeBuildKey(typeToBuild);
 }
Esempio n. 6
0
 /// <summary>
 /// Create a new <see cref="BuilderContext"/> using the explicitly provided
 /// values.
 /// </summary>
 /// <param name="chain">The <see cref="IStrategyChain"/> to use for this context.</param>
 /// <param name="lifetime">The <see cref="ILifetimeContainer"/> to use for this context.</param>
 /// <param name="persistentPolicies">The set of persistent policies to use for this context.</param>
 /// <param name="transientPolicies">The set of transient policies to use for this context. It is
 /// the caller's responsibility to ensure that the transient and persistent policies are properly
 /// combined.</param>
 /// <param name="buildKey">Build key for this context.</param>
 /// <param name="existing">Existing object to build up.</param>
 public BuilderContext(IStrategyChain chain, ILifetimeContainer lifetime, IPolicyList persistentPolicies, IPolicyList transientPolicies, NamedTypeBuildKey buildKey, object existing)
 {
     this.chain              = chain;
     this.lifetime           = lifetime;
     this.persistentPolicies = persistentPolicies;
     this.policies           = transientPolicies;
     this.originalBuildKey   = buildKey;
     this.BuildKey           = buildKey;
     this.Existing           = existing;
 }
 public static T NewBuildUp <T>(IBuilderContext context)
 {
     return((T)context.NewBuildUp(NamedTypeBuildKey.Make <T>()));
 }
 public static TResult NewBuildUp <TResult>(this IBuilderContext context, string name)
 {
     Guard.ArgumentNotNull(context, "context");
     return((TResult)context.NewBuildUp(NamedTypeBuildKey.Make <TResult>(name)));
 }
 public static TResult NewBuildUp <TResult>(this IBuilderContext context, string name)
 {
     return((TResult)context.NewBuildUp(NamedTypeBuildKey.Make <TResult>(name)));
 }