I have a .NET3.0 program I am moving to .NET6. We use Castle.DynamicProxy to intercept calls to certain methods and then log the parameter those methods was called with. In .NET3 to add this to the class MyController we use
IWindsorContainer container;
_container = container;
container.Register(Component.For<MyController>().ImplementedBy<MyController>().LifeStyle.Transient
.Interceptors(InterceptorReference.ForType<LogInterceptor>()).Anywhere);
The syntax is different in .NET6 and I have tried with out luck
builder.Services.AddInterceptedSingleton<IMyController, MyController, LogInterceptor>();
I have also tried
builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory());
builder.Host.ConfigureContainer<ContainerBuilder>(builder =>
{
builder.RegisterType<MyController>().As<IMyController>().EnableClassInterceptors();
});
The basis of LogInterceptor.cs
public class LogInterceptor: IInterceptor
{
public void Intercept(IInvocation invocation)
{
}
LogAttribute logAttribute = GetLogAttribute(invocation);
if logAttribute == null)
{
invocation.Proceed();
return;
}
switch (logAttribute.logType)
{
.... //Logic for the switch
}