Originally, you helped me out with getting all the decorators attached using open generics here.
https://groups.google.com/forum/#!searchin/autofac/brantley/autofac/lV2X4hR0mak/F5g4MfhUR08J
That has been working great and I modified the code so you could pass in a list of decorators to apply (decorators decorating decorators). For completeness here is that code (in case someone wants it):
public static IRegistrationBuilder<TLimit, TScanningActivatorData, TRegistrationStyle> AsClosedTypesOfWithDecorators<TLimit, TScanningActivatorData, TRegistrationStyle>(
this IRegistrationBuilder<TLimit, TScanningActivatorData, TRegistrationStyle> registration,
ContainerBuilder builder, Type commandType, params Type[] decorators) where TScanningActivatorData : ScanningActivatorData
{
if (commandType == null) throw new ArgumentNullException(nameof(commandType));
if (decorators == null || decorators.Length == 0)
return registration.AsClosedTypesOf(commandType);
string actualHandler = Guid.NewGuid().ToString();
var returnValue = registration
.AsNamedClosedTypesOf(commandType, t => actualHandler);
string lastHandler = actualHandler;
var lastDecorator = decorators.Last();
foreach (var decorator in decorators) //take all but last decorator...it cannot be keyed..
{
var newKey = Guid.NewGuid().ToString();
var decoratorRegistration = builder.RegisterGenericDecorator(
decorator,
commandType, lastHandler);
if (decorator != lastDecorator) //cannot key the last decorator...
decoratorRegistration.Keyed(newKey, commandType);
lastHandler = newKey;
}
return returnValue;
}
Anyway, the big issue at hand is conditionally registering decorators. This is a shortcoming I have been working around for a while and last April you said may focus on it after DNX settle down (
https://groups.google.com/forum/#!searchin/autofac/decorator/autofac/vSU6kx7XX2M/AxhpHqddGzkJ)
However, I now have a really wild situation that I cannot resolve.
1) I register all my query/commands with decorators using the above code. All good.
2) I hand register each query/command SECOND time which effectively hides the first registration. On this I use the non-open generic RegisterType<> and RegisterDecorator<> to filter out the decorators I do not want for these specific commands/queries.
This seems to work great. I open my web application and sure enough the new registration is being applied and there are no issues.
The issue is that if I do a WEBAPI request - it continues to use the original registration and not the new one!! I have pulled my hair out on this issue.
Any ideas?