public InjectionAttribute(ServiceLifetime lifetime = ServiceLifetime.Scoped, InjectionPolicy policy = InjectionPolicy.Append, params Type[] serviceTypes) { ServiceTypes = serviceTypes; Lifetime = lifetime; Policy = policy; }
public InjectionAttribute(Type serviceType, ServiceLifetime lifetime = ServiceLifetime.Scoped, InjectionPolicy policy = InjectionPolicy.Append) { ServiceType = serviceType; Lifetime = lifetime; Policy = policy; }
public void ShouldHaveNoHandlersWhenPolicyDoesntMatch() { IMatchingRule[] rules = { }; IUnityContainer container = CreateConfiguredContainer(); InjectionPolicy p = CreatePolicy(container, rules); MethodImplementationInfo thisMember = GetMethodImplInfo <PolicyFixture>("ShouldHaveNoHandlersWhenPolicyDoesntMatch"); List <ICallHandler> memberHandlers = new List <ICallHandler>(p.GetHandlersFor(thisMember, container)); Assert.AreEqual(0, memberHandlers.Count); }
public void ShouldGetHandlersInOrderWithGetHandlersFor() { IMatchingRule[] rules = { new MemberNameMatchingRule("ShouldGetHandlersInOrderWithGetHandlersFor") }; IUnityContainer container = CreateConfiguredContainer(); InjectionPolicy p = CreatePolicy(container, rules); MethodImplementationInfo member = GetMethodImplInfo <PolicyFixture>("ShouldGetHandlersInOrderWithGetHandlersFor"); List <ICallHandler> expectedHandlers = new List <ICallHandler>(container.ResolveAll <ICallHandler>()); List <ICallHandler> actualHandlers = new List <ICallHandler>(p.GetHandlersFor(member, container)); CollectionAssertExtensions.AreEqual( expectedHandlers, actualHandlers, new TypeComparer()); }
public void ShouldBeAbleToMatchPropertyGet() { IMatchingRule[] rules = { new MemberNameMatchingRule("get_Balance") }; IUnityContainer container = CreateConfiguredContainer(); InjectionPolicy p = CreatePolicy(container, rules); PropertyInfo balanceProperty = typeof(MockDal).GetProperty("Balance"); MethodImplementationInfo getMethod = new MethodImplementationInfo(null, balanceProperty.GetGetMethod()); List <ICallHandler> expectedHandlers = new List <ICallHandler>(container.ResolveAll <ICallHandler>()); List <ICallHandler> actualHandlers = new List <ICallHandler>(p.GetHandlersFor(getMethod, container)); CollectionAssertExtensions.AreEqual( expectedHandlers, actualHandlers, new TypeComparer()); }
/// <summary> /// Intercepts an exported value. /// </summary> /// <param name="value">The value to be intercepted.</param> /// <returns>Intercepted value.</returns> public object Intercept(object value) { var interfaces = value.GetType().GetInterfaces(); var proxyInterface = interfaces.FirstOrDefault(); var additionalInterfaces = interfaces.Skip(1).ToArray(); CurrentInterceptionRequest request = new CurrentInterceptionRequest(interceptor, proxyInterface, value.GetType()); InjectionPolicy[] policies = new InjectionPolicy[] { new AttributeDrivenPolicy() }; PolicyInjectionBehavior behaviour = new PolicyInjectionBehavior(request, policies, null); var proxy = Microsoft.Practices.Unity.InterceptionExtension.Intercept.ThroughProxyWithAdditionalInterfaces( proxyInterface, value, interceptor, new[] { behaviour }, additionalInterfaces); return(proxy); }
public InjectionAttribute(InjectionPolicy policy) { Policy = policy; }
private static void AddService(IServiceCollection serviceCollection, Type serviceType, Type implementationType, ServiceLifetime lifetime, InjectionPolicy policy) { var descriptor = new ServiceDescriptor(serviceType, implementationType, lifetime); switch (policy) { case InjectionPolicy.Append: serviceCollection.TryAddEnumerable(descriptor); break; case InjectionPolicy.Skip: serviceCollection.TryAdd(descriptor); break; case InjectionPolicy.Replace: serviceCollection.Replace(descriptor); break; } }