builder.RegisterType(typeof(AInterface))
.EnableInterfaceInterceptors()
.InterceptedBy(typeof(AInterceptor));
But it does not support in autofac,
so I use another way to finish it with "ProxyGen.CreateInterfaceProxyWithoutTarget":
assembly.GetTypes().Where(x => x.IsInterface && x.GetInterfaces().Any(t => t == (typeof(IDao))))
.ToList().ForEach(t =>
{
builder.Register(x =>
{
ProxyGenerator proxyGen = new ProxyGenerator();
return proxyGen.CreateInterfaceProxyWithoutTarget(t, new SqlMapperInterceptor());
}).As(t);
});
can autofac provide a way to finish this feature?
This is a great way to provide a configuration stub during tests but maintaining the real implementation to retrieve values from app.config using ConfigurationManager.AppSettings is a hassle due to the use of magic strings and then performing explicit type conversions from string to other value types.
An interceptor provides a clean way to provide all of the behavior necessary to retrieve values from app.config, providing the property name as the config key and then performing the appropriate type conversion. Of course, if the keys don't match the property names on the interface then you're in trouble but this is a risk regardless.
Maintaining a separate dummy class in this scenario seems like redundant overhead.
This type of usage is also being used by Autofac's Aggregate Services package.