private static void BuildResolveEnumerable <T>(IBuilderContext context) { if (null == context.Existing) { var key = context.BuildKey; var type = key.Type; var itemType = type.GetTypeInfo().GenericTypeArguments[0]; var itemTypeInfo = itemType.GetTypeInfo(); var container = context.Container ?? context.NewBuildUp <IUnityContainer>(); if (itemTypeInfo.IsGenericTypeDefinition) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.MustHaveOpenGenericType, itemType.GetTypeInfo().Name)); } var generic = new Lazy <Type>(() => itemType.GetGenericTypeDefinition()); IEnumerable <object> enumerable = container.Registrations .Where(r => r.RegisteredType == itemType || (itemTypeInfo.IsGenericType && r.RegisteredType.GetTypeInfo().IsGenericTypeDefinition&& r.RegisteredType == generic.Value)) .Select(r => context.NewBuildUp(new NamedTypeBuildKey(itemType, r.Name))); context.Existing = CastMethod.MakeGenericMethod(itemType).Invoke(null, new object[] { enumerable }); context.BuildComplete = true; } // match the behavior of DynamicMethodConstructorStrategy DynamicMethodConstructorStrategy.SetPerBuildSingleton(context); }
private ValidatorFactory GetValidatorFactory(IBuilderContext context) { var validationSpecificationSource = ValidationSource(context); if (validationSpecificationSource == 0) { throw new InvalidOperationException( string.Format(CultureInfo.CurrentCulture, Resources.InvalidValidationSpecificationSource, validationSpecificationSource)); } if (validationSpecificationSource == ValidationSpecificationSource.All) { return(context.NewBuildUp <ValidatorFactory>()); } var factories = new List <ValidatorFactory>(); if ((validationSpecificationSource & ValidationSpecificationSource.Attributes) != 0) { factories.Add(context.NewBuildUp <AttributeValidatorFactory>()); } if ((validationSpecificationSource & ValidationSpecificationSource.Configuration) != 0) { factories.Add(context.NewBuildUp <ConfigurationValidatorFactory>()); } if ((validationSpecificationSource & ValidationSpecificationSource.DataAnnotations) != 0) { factories.Add(context.NewBuildUp <ValidationAttributeValidatorFactory>()); } return(new CompositeValidatorFactory(GetInstrumentationProvider(context), factories)); }
private static object ResolveArray <T>(IBuilderContext context) { IUnityContainer container = context.NewBuildUp <IUnityContainer>(); var registrations = container.Registrations; if (typeof(T).IsGenericType) { registrations = registrations .Where(registration => registration.RegisteredType == typeof(T) || registration.RegisteredType == typeof(T).GetGenericTypeDefinition()); } else { registrations = registrations .Where(registration => registration.RegisteredType == typeof(T)); } var registeredNames = registrations .Select(registration => registration.Name) // note: including empty ones .Distinct() .ToList(); var results = registeredNames .Select(name => context.NewBuildUp <T>(name)) .ToArray(); return(results); }
private object Resolve(object attr, FieldInfo field, IBuilderContext context) { Trace.WriteLine(string.Format("Resolving Autowired property - {0} of type {1}", field.Name, context.Existing.GetType())); object returnval = null; AutowireAttribute autowireAttr = attr as AutowireAttribute; var ignoreCache = context.Existing.GetType().GetCustomAttribute <IgnoreAutowireCacheAttribute>(); if (ignoreCache == null) { var interfaces = context.Existing.GetType().GetInterfaces(); foreach (var iface in interfaces) { var currentObjectCacheKey = iface.FullName + "|" + (context.BuildKey.Name ?? ""); if (!_instanceCache.ContainsKey(currentObjectCacheKey)) { _instanceCache[currentObjectCacheKey] = context.Existing; } } } string cacheKey = field.FieldType.FullName + "|" + (autowireAttr.ScopeName ?? ""); Trace.WriteLine("Cache key = {0}", cacheKey); if (_instanceCache.ContainsKey(cacheKey)) { return(_instanceCache[cacheKey]); } Trace.WriteLine("Autowired instance Not found in cache"); if (string.IsNullOrWhiteSpace(autowireAttr.ScopeName)) { try { Trace.WriteLine("Resolving in default scope"); returnval = context.NewBuildUp(new NamedTypeBuildKey(field.FieldType)); } catch (Exception) { Trace.WriteLine("Could not get concrete object"); throw; } } else { Trace.WriteLine(string.Format("Resolving in {0} scope", autowireAttr.ScopeName)); returnval = context.NewBuildUp(new NamedTypeBuildKey(field.FieldType, autowireAttr.ScopeName)); } if (returnval != null) { ignoreCache = returnval.GetType().GetCustomAttribute <IgnoreAutowireCacheAttribute>(); if (ignoreCache == null) { _instanceCache[cacheKey] = returnval; } } return(returnval); }
private static object ResolveCollection <T>(IBuilderContext context) { IUnityContainer container = context.NewBuildUp <IUnityContainer>(); var extractor = context.NewBuildUp <ResolverOverrideExtractor>(); var resolverOverrides = extractor.ExtractResolverOverrides(context); List <T> results = new List <T>(container.ResolveAll <T>(resolverOverrides)); return(results); }
public override void PostBuildUp(IBuilderContext context) { if (context.Existing is IInterceptingProxy || !_interfaceInterceptor.CanIntercept(context.OriginalBuildKey.Type)) return; if (!context.Existing.GetType().HasCustomerAttributes<LogAttribute>()) return; //var methods = _interfaceInterceptor.GetInterceptableMethods(context.OriginalBuildKey.Type, context.BuildKey.Type); var loggingInterceptionBehavior = new LoggingInterfaceMethodBehavior(context.NewBuildUp<ILogMethodInvocation>(), context.NewBuildUp<PropertyMappingDictionary>(), context.Existing.GetType()); context.Existing = Intercept.ThroughProxy(context.OriginalBuildKey.Type, context.Existing, _interfaceInterceptor, new[] { loggingInterceptionBehavior }); }
public override void PreBuildUp(IBuilderContext context) { var key = context.OriginalBuildKey; if (!(key.Type.IsInterface && _typeStacks.ContainsKey(key.Type)) || context.GetOverriddenResolver(key.Type) != null) { return; } var stack = _typeStacks[key.Type]; object value = null; while (stack.Count != 0) { var t = stack.Dequeue(); value = context.NewBuildUp(t, key.Name); var overrides = new DependencyOverride( key.Type, value); context.AddResolverOverrides(overrides); } context.Existing = value; context.BuildComplete = true; }
public override void PreBuildUp(IBuilderContext context) { var key = context.OriginalBuildKey; if (!key.Type.IsInterface || context.GetOverriddenResolver(key.Type) != null) { return; } Stack <Type> stack; if (!_stackDictionary.TryGetValue(key.Type, out stack)) { return; } object value = null; foreach (var t in stack) { value = context.NewBuildUp(new NamedTypeBuildKey(t, key.Name)); var overrides = new DependencyOverride(key.Type, value); context.AddResolverOverrides(overrides); } context.Existing = value; context.BuildComplete = true; }
/// <summary> /// Do the PreBuildUp stage of construction. This is where the actual work is performed. /// </summary> /// <param name="context">Current build context.</param> public override void PreBuildUp(IBuilderContext context) { Guard.ArgumentNotNull(context, "context"); if (!IsResolvingIEnumerable(context.BuildKey.Type)) { return; } var container = context.NewBuildUp <IUnityContainer>(); if (container.IsRegistered(context.BuildKey.Type)) { return; } MethodInfo resolverMethod; var typeToBuild = GetTypeToBuild(context.BuildKey.Type); if (IsResolvingLazy(typeToBuild)) { typeToBuild = GetTypeToBuild(typeToBuild); resolverMethod = GenericResolveLazyEnumerableMethod.MakeGenericMethod(typeToBuild); } else { resolverMethod = GenericResolveEnumerableMethod.MakeGenericMethod(typeToBuild); } var resolver = (Resolver)Delegate.CreateDelegate(typeof(Resolver), resolverMethod); context.Existing = resolver(context, container); context.BuildComplete = true; }
/// <summary> /// Get the value for a dependency. /// </summary> /// <param name="context">Current build context.</param> /// <returns> /// The value for the dependency. /// </returns> public object Resolve(IBuilderContext context) { return context.NewBuildUp(new NamedTypeBuildKey(validatorType, ruleSet), newContext => newContext.Policies.Set( new ValidationSpecificationSourcePolicy(validationSource), new NamedTypeBuildKey(validatorType, ruleSet))); }
private static object ResolveArray <T>(IBuilderContext context) { IUnityContainer container = context.NewBuildUp <IUnityContainer>(); List <T> results = new List <T>(container.ResolveAll <T>()); return(results.ToArray()); }
/// <summary> /// Called during the chain of responsibility for a build operation. /// Looks for the <see cref="IBuildKeyMappingPolicy"/> /// and if found maps the build key for the current operation. /// </summary> /// <param name="context">The context for the operation.</param> public override void PreBuildUp(IBuilderContext context) { Guard.ArgumentNotNull(context, "context"); var policy = context.Policies.Get <IBuildKeyMappingPolicy>(context.BuildKey); if (policy == null) { return; } var key = policy.Map(context.BuildKey, context); if (key == context.BuildKey) { return; } var existing = context.NewBuildUp(context.BuildKey, (child) => { child.Existing = context.Existing; child.BuildKey = key; }); if (null != existing) { context.Existing = existing; context.BuildComplete = true; } }
public override void PreBuildUp(IBuilderContext context) { NamedTypeBuildKey key = context.OriginalBuildKey; if (!(key.Type.IsInterface && _typeStacks.ContainsKey(key.Type))) { return; } if (null != context.GetOverriddenResolver(key.Type)) { return; } var stack = new Stack<Type>(_typeStacks[key.Type]); object value = null; stack.ForEach(type => { value = context.NewBuildUp(new NamedTypeBuildKey(type, key.Name)); var overrides = new DependencyOverride(key.Type, value); context.AddResolverOverrides(overrides); } ); context.Existing = value; context.BuildComplete = true; }
public void BuildUp(IBuilderContext context) { Guard.ArgumentNotNull(context, "context"); if (context.Existing == null) { var currentContainer = context.NewBuildUp <IUnityContainer>(); Type typeToBuild = GetTypeToBuild(context.BuildKey.Type); string nameToBuild = context.BuildKey.Name; Delegate resolveMethod; if (IsResolvingIEnumerable(typeToBuild)) { resolveMethod = CreateResolveAllResolver(currentContainer, typeToBuild); } else { resolveMethod = CreateResolver(currentContainer, typeToBuild, nameToBuild); } context.Existing = resolveMethod; DynamicMethodConstructorStrategy.SetPerBuildSingleton(context); } }
public override void PreBuildUp(IBuilderContext context) { Guard.ArgumentNotNull(context, "context"); if (!this.CanIntercept(context)) { return; } IInstanceInterceptionPolicy interceptionPolicy = FindInterceptionPolicy <IInstanceInterceptionPolicy>(context, true); if (null == interceptionPolicy) { IInstanceInterceptor interceptor = context.NewBuildUp <IInterceptor>(typeof(IInterceptor).AssemblyQualifiedName) as IInstanceInterceptor; if (null == interceptor) { return; } if (!interceptor.CanIntercept(context.BuildKey.Type)) { return; } context.Policies.Set <IInstanceInterceptionPolicy>(new FixedInstanceInterceptionPolicy(interceptor), context.BuildKey); context.Policies.Clear <ITypeInterceptionPolicy>(context.BuildKey); } IInterceptionBehaviorsPolicy interceptionBehaviorsPolicy = FindInterceptionPolicy <IInterceptionBehaviorsPolicy>(context, true); if (null == interceptionBehaviorsPolicy) { var policyInjectionBehavior = new InterceptionBehavior <PolicyInjectionBehavior>(); policyInjectionBehavior.AddPolicies(context.OriginalBuildKey.Type, context.BuildKey.Type, context.BuildKey.Name, context.Policies); } }
public override void PreBuildUp(IBuilderContext context) { NamedTypeBuildKey key = context.OriginalBuildKey; if (!(key.Type.IsInterface && _typeStacks.ContainsKey(key.Type))) { return; } if (null != context.GetOverriddenResolver(key.Type)) { return; } var stack = new Stack <Type>(_typeStacks[key.Type]); object value = null; stack.ForEach(type => { value = context.NewBuildUp(new NamedTypeBuildKey(type, key.Name)); var overrides = new DependencyOverride(key.Type, value); context.AddResolverOverrides(overrides); } ); context.Existing = value; context.BuildComplete = true; }
/// <summary> /// Get the value for a dependency. /// </summary> /// <param name="context">Current build context.</param> /// <returns> /// The value for the dependency. /// </returns> public object Resolve(IBuilderContext context) { return(context.NewBuildUp(new NamedTypeBuildKey(validatorType, ruleSet), newContext => newContext.Policies.Set( new ValidationSpecificationSourcePolicy(validationSource), new NamedTypeBuildKey(validatorType, ruleSet)))); }
public object Resolve(IBuilderContext context) { var lifetimeManager = new ContainerControlledLifetimeManager(); lifetimeManager.SetValue(_logSourceType); var loggerNameKey = new NamedTypeBuildKey(typeof(Type), "LogSourceType"); //Create the build context for the logger var newKey = new NamedTypeBuildKey(_type, _name); //Register the item as a transient policy context.Policies.Set <IBuildKeyMappingPolicy>(new BuildKeyMappingPolicy(loggerNameKey), loggerNameKey); context.Policies.Set <ILifetimePolicy>(lifetimeManager, loggerNameKey); context.Lifetime.Add(lifetimeManager); try { return(context.NewBuildUp(newKey)); } finally { context.Lifetime.Remove(lifetimeManager); context.Policies.Clear <IBuildKeyMappingPolicy>(loggerNameKey); context.Policies.Clear <ILifetimePolicy>(loggerNameKey); } }
/// <summary> /// Get the value for a dependency. /// </summary> /// <param name="context">Current build context.</param> /// <returns>The value for the dependency.</returns> public object Resolve(IBuilderContext context) { if (context == null) { throw new ArgumentNullException("context"); } return(context.NewBuildUp(new NamedTypeBuildKey(typeToBuild))); }
private static object ResolveEnumerable <T>(IBuilderContext context) { var container = context.NewBuildUp <IUnityContainer>(); var typeToBuild = typeof(T); var results = ResolveAll(container, typeToBuild, typeToBuild).OfType <T>().ToList(); return(results); }
/// <summary> /// Get the value for a dependency. /// </summary> /// <param name="context">Current build context.</param> /// <returns>The value for the dependency.</returns> public object Resolve(IBuilderContext context) { if (context == null) { throw new ArgumentNullException("context"); } return context.NewBuildUp(new NamedTypeBuildKey(typeToBuild)); }
private static object ResolveLazyEnumerable <T>(IBuilderContext context) { var container = context.NewBuildUp <IUnityContainer>(); var typeToBuild = typeof(T); var typeWrapper = typeof(Lazy <T>); return(ResolveAll(container, typeToBuild, typeWrapper).OfType <Lazy <T> >().ToList());; }
private static ISettingsFactory GetSettingsFactory(IBuilderContext context) { var factory = context.NewBuildUp<ISettingsFactory>("DefaultSettingsFactory"); if (factory == null) { throw new InvalidOperationException("No instance of ISettingsFactory available."); } return factory; }
private EventBroker GetBroker(IBuilderContext context) { var broker = context.NewBuildUp<EventBroker>(); if(broker == null) { throw new InvalidOperationException("No event broker available"); } return broker; }
/// <summary> /// Creates an instance of this build plan's type, or fills /// in the existing type if passed in. /// </summary> /// <param name="context">Context used to build up the object.</param> public void BuildUp(IBuilderContext context) { if ((context ?? throw new ArgumentNullException(nameof(context))).Existing == null) { var currentContainer = context.NewBuildUp <IUnityContainer>(); context.Existing = factory(currentContainer, context.BuildKey.Type, context.BuildKey.Name); context.SetPerBuildSingleton(); } }
/// <summary> /// Creates an instance of this build plan's type, or fills /// in the existing type if passed in. /// </summary> /// <param name="context">Context used to build up the object.</param> public void BuildUp(IBuilderContext context) { if (context.Existing == null) { var currentContainer = context.NewBuildUp <IUnityContainer>(); context.Existing = factory(currentContainer, context.BuildKey.Type, context.BuildKey.Name); DynamicMethodConstructorStrategy.SetPerBuildSingleton(context); } }
private EventBroker GetBroker(IBuilderContext context) { var broker = context.NewBuildUp <EventBroker>(); if (broker == null) { throw new InvalidOperationException("No event broker available"); } return(broker); }
/// <summary> /// Creates an instance of this build plan's type, or fills /// in the existing type if passed in. /// </summary> /// <param name = "context">Context used to build up the object.</param> public void BuildUp(IBuilderContext context) { if (context.Existing == null) { var currentContainer = context.NewBuildUp<IUnityContainer>(); context.Existing = factory(currentContainer, context.BuildKey.Type, context.BuildKey.Name); DynamicMethodConstructorStrategy.SetPerBuildSingleton(context); } }
public override void PreBuildUp(IBuilderContext context) { var type = context.BuildKey.Type; var target = context.Existing; if (!type.FullName.StartsWith("Microsoft.Practices")) { unityContainer.SetProperties(target.GetType(), target, t => context.NewBuildUp(new NamedTypeBuildKey(t))); } }
/// <summary> /// Resolve object from given context. /// </summary> /// <param name="context"></param> /// <returns></returns> public object Resolve(IBuilderContext context) { var uri = (string) _uriResolver.Resolve(context); var resourceLoader = context.NewBuildUp<ResourceLoader>(); if (_many) { return resourceLoader.GetResources(uri); } return resourceLoader.GetResource(uri); }
public void BuildUp(IBuilderContext context) { if (context.Existing == null) { // build up dependencies var behavior = context.NewBuildUp <DIServiceBehavior <TInterface, TImplementation> >(); // create new DIServiceHost var serviceHost = new DIServiceHost <TInterface, TImplementation>(behavior); // add behaviors to ServiceHost foreach (var behaviorType in behaviors) { var newBehavior = context.NewBuildUp(new NamedTypeBuildKey(behaviorType)) as IServiceBehavior; serviceHost.Description.Behaviors.Add(newBehavior); } // add service endpoints to ServiceHost endpoints.ForEach(s => serviceHost.AddServiceEndpoint(s.Type, s.Binding, s.Address)); context.Existing = serviceHost; } }
/// <summary> /// Resolve object from given context. /// </summary> /// <param name="context"></param> /// <returns></returns> public object Resolve(IBuilderContext context) { var uri = (string)_uriResolver.Resolve(context); var resourceLoader = context.NewBuildUp <ResourceLoader>(); if (_many) { return(resourceLoader.GetResources(uri)); } return(resourceLoader.GetResource(uri)); }
private static void BuildResolveAllLazy <T>(IBuilderContext context) { if (context.Existing == null) { var container = context.Container ?? context.NewBuildUp <IUnityContainer>(); context.Existing = new Lazy <IEnumerable <T> >(() => container.ResolveAll <T>()); } // match the behavior of DynamicMethodConstructorStrategy DynamicMethodConstructorStrategy.SetPerBuildSingleton(context); }
private static IValidationInstrumentationProvider GetInstrumentationProvider(IBuilderContext context) { var mapping = context.Policies.Get <IBuildKeyMappingPolicy>( NamedTypeBuildKey.Make <IValidationInstrumentationProvider>()); if (mapping != null) { return(context.NewBuildUp <IValidationInstrumentationProvider>()); } return(null); }
public override void PostBuildUp(IBuilderContext context) { var proxy = context.Existing as IInterceptingProxy; if (proxy == null || context.Policies.Get<InterceptVirtualMethodPolicy>(context.BuildKey) == null) return; //var methods = _virtualMethodInterceptor.GetInterceptableMethods(context.OriginalBuildKey.Type, context.BuildKey.Type); //proxy.AddInterceptionBehavior(new LoggingVirtualMethodBehavior(context.NewBuildUp<ILogger>(), context.NewBuildUp<PropertyMappingDictionary>())); proxy.AddInterceptionBehavior(context.NewBuildUp<LoggingVirtualMethodBehavior>()); }
public void BuildUp(IBuilderContext context) { Microsoft.Practices.Unity.Utility.Guard.ArgumentNotNull(context, "context"); if(context.Existing == null) { var currentContainer = context.NewBuildUp<IUnityContainer>(); context.Existing = factory(currentContainer, context.BuildKey.Type, context.BuildKey.Name); DynamicMethodConstructorStrategy.SetPerBuildSingleton(context); } }
private static void BuildResolveLazy <T>(IBuilderContext context) { if (context.Existing == null) { var name = context.BuildKey.Name; var container = context.NewBuildUp <IUnityContainer>(); context.Existing = new Lazy <T>(() => container.Resolve <T>(name)); } // match the behavior of DynamicMethodConstructorStrategy DynamicMethodConstructorStrategy.SetPerBuildSingleton(context); }
/// <summary> /// Creates an instance of this build plan's type, or fills /// in the existing type if passed in. /// </summary> /// <param name="context">Context used to build up the object.</param> public void BuildUp(IBuilderContext context) { Unity.Utility.Guard.ArgumentNotNull(context, "context"); if (context.Existing == null) { var currentContainer = context.Container ?? context.NewBuildUp <IUnityContainer>(); context.Existing = factory(currentContainer, context.BuildKey.Type, context.BuildKey.Name); DynamicMethodConstructorStrategy.SetPerBuildSingleton(context); } }
public override void PreBuildUp(IBuilderContext context) { if (context.Existing == null) { var policy = context.Policies.Get<IAutoFactoryPolicy>(context.OriginalBuildKey); if (policy != null) { var autoFactoryType = AutoFactoryTypeGenerator.GetAutoFactoryType(context.OriginalBuildKey.Type, policy.ConcreteResultType); context.Existing = context.NewBuildUp(new NamedTypeBuildKey(autoFactoryType, context.OriginalBuildKey.Name)); } } base.PreBuildUp(context); }
public override void PreBuildUp(IBuilderContext context) { if (context.Existing == null) { var policy = context.Policies.Get<ILazyProxyPolicy>(context.OriginalBuildKey); if (policy != null) { var lazyProxyType = LazyProxyGenerator.GetLazyProxyType(policy.ServiceType, policy.ImplementationType); context.Existing = context.NewBuildUp(new NamedTypeBuildKey(lazyProxyType, context.OriginalBuildKey.Name)); } } base.PreBuildUp(context); }
/// <summary> /// Get the set of <see cref="IInterceptionBehavior"/> object to be used for the given type and /// interceptor. /// </summary> /// <remarks> /// This method will return a sequence of <see cref="IInterceptionBehavior"/>s. These behaviors will /// only be included if their <see cref="IInterceptionBehavior.WillExecute"/> properties are true. /// </remarks> /// <param name="context">Context for the current build operation.</param> /// <param name="interceptor">Interceptor that will be used to invoke the behavior.</param> /// <param name="typeToIntercept">Type that interception was requested on.</param> /// <param name="implementationType">Type that implements the interception.</param> /// <returns></returns> public IEnumerable <IInterceptionBehavior> GetEffectiveBehaviors( IBuilderContext context, IInterceptor interceptor, Type typeToIntercept, Type implementationType) { var interceptionRequest = new CurrentInterceptionRequest(interceptor, typeToIntercept, implementationType); foreach (var key in BehaviorKeys) { var behavior = (IInterceptionBehavior)context.NewBuildUp(key, childContext => childContext.AddResolverOverrides( new DependencyOverride <CurrentInterceptionRequest>(interceptionRequest))); yield return(behavior); } }
public override void PreBuildUp(IBuilderContext context) { if (context.Existing == null) { var policy = context.Policies.Get <ILazyProxyPolicy>(context.OriginalBuildKey); if (policy != null) { var lazyProxyType = LazyProxyGenerator.GetLazyProxyType(policy.ServiceType, policy.ImplementationType); context.Existing = context.NewBuildUp(new NamedTypeBuildKey(lazyProxyType, context.OriginalBuildKey.Name)); } } base.PreBuildUp(context); }
/// <summary> /// Get the set of <see cref="IInterceptionBehavior"/> object to be used for the given type and /// interceptor. /// </summary> /// <remarks> /// This method will return a sequence of <see cref="IInterceptionBehavior"/>s. These behaviors will /// only be included if their <see cref="IInterceptionBehavior.WillExecute"/> properties are true. /// </remarks> /// <param name="context">Context for the current build operation.</param> /// <param name="interceptor">Interceptor that will be used to invoke the behavior.</param> /// <param name="typeToIntercept">Type that interception was requested on.</param> /// <param name="implementationType">Type that implements the interception.</param> /// <returns></returns> public IEnumerable<IInterceptionBehavior> GetEffectiveBehaviors( IBuilderContext context, IInterceptor interceptor, Type typeToIntercept, Type implementationType) { var interceptionRequest = new CurrentInterceptionRequest(interceptor, typeToIntercept, implementationType); foreach (var key in BehaviorKeys) { var behavior = (IInterceptionBehavior)context.NewBuildUp(key, childContext => childContext.AddResolverOverrides( new DependencyOverride<CurrentInterceptionRequest>(interceptionRequest))); yield return behavior; } }
public object Resolve(IBuilderContext context) { Guard.ArgumentNotNull(context, "context"); var newKey = new NamedTypeBuildKey(type, name); try { return context.NewBuildUp(newKey); } catch (Exception) { return null; } }
public object Resolve(IBuilderContext context) { Guard.ArgumentNotNull(context, "context"); return context.NewBuildUp(new NamedTypeBuildKey(type, name)); }
private ValidatorFactory GetValidatorFactory(IBuilderContext context) { var validationSpecificationSource = ValidationSource(context); if(validationSpecificationSource == 0) { throw new InvalidOperationException( string.Format(CultureInfo.CurrentCulture, Resources.InvalidValidationSpecificationSource, validationSpecificationSource)); } if(validationSpecificationSource == ValidationSpecificationSource.All) { return context.NewBuildUp<ValidatorFactory>(); } var factories = new List<ValidatorFactory>(); if((validationSpecificationSource & ValidationSpecificationSource.Attributes) != 0) { factories.Add(context.NewBuildUp<AttributeValidatorFactory>()); } if((validationSpecificationSource & ValidationSpecificationSource.Configuration) != 0) { factories.Add(context.NewBuildUp<ConfigurationValidatorFactory>()); } if((validationSpecificationSource & ValidationSpecificationSource.DataAnnotations) != 0) { factories.Add(context.NewBuildUp<ValidationAttributeValidatorFactory>()); } return new CompositeValidatorFactory(GetInstrumentationProvider(context), factories); }
public ITypeInterceptor GetInterceptor(IBuilderContext context) { Guard.ArgumentNotNull(context, "context"); return (ITypeInterceptor) context.NewBuildUp(buildKey); }
public object Resolve(IBuilderContext context) { Guard.ArgumentNotNull(context, "context"); return context.NewBuildUp(keyToBuild); }
public IDynamicInterceptor Retrieve(IBuilderContext builderContext) { return (IDynamicInterceptor)builderContext.NewBuildUp(new NamedTypeBuildKey(this.interceptorType, builderContext.BuildKey.Name)); }
private static IValidationInstrumentationProvider GetInstrumentationProvider(IBuilderContext context) { var mapping = context.Policies.Get<IBuildKeyMappingPolicy>( NamedTypeBuildKey.Make<IValidationInstrumentationProvider>()); if(mapping != null) { return context.NewBuildUp<IValidationInstrumentationProvider>(); } return null; }