(This question is related to this , which is for SimpleInjector. I was recommended to create separate questions for each IoC container.)
With Unity, I can quickly add attribute-based interception like this
public sealed class MyCacheAttribute : HandlerAttribute, ICallHandler
{
public override ICallHandler CreateHandler(IUnityContainer container)
{
return this;
}
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
}
}
Then I register with Unity as follows:
container.RegisterType<IPlanRepository, PlanRepository>(new ContainerControlledLifetimeManager(),
new Interceptor<VirtualMethodInterceptor>(),
new InterceptionBehavior<PolicyInjectionBehavior>());
In my repository code, I can selectively decorate certain methods that need to be cached (with attribute values that can be individually configured for each method):
[MyCache( Minutes = 5, CacheType = CacheType.Memory, Order = 100)]
public virtual PlanInfo GetPlan(int id)
{
}
Autofac. , , , / . . ?