I'm trying to apply autofac decorator support feature to my scenario with no success. It looks like in my case it doesn't assign the name to the registrations properly.
Is there a way to register scanned assembly types with a name, so that I can later use it in the open generic decorator key?
Or maybe I'm completely wrong and doing something inappropriate here?
builder.RegisterAssemblyTypes(typeof(IAggregateRepositoryAssembly).Assembly)
.AsClosedTypesOf(typeof(IAggregateViewRepository<>)) //here I need name, probably
.Named("view-implementor", typeof(IAggregateViewRepository<>))
.SingleInstance();
builder.RegisterGenericDecorator(typeof(CachedAggregateViewRepository<>),
typeof(IAggregateViewRepository<>), fromKey: "view-implementor");
Here's an attempt, not in front of Visual Studio so overload resolution might not be exactly right:
Named()
is just syntactic sugar forKeyed()
, which associates the component with aKeyedService
As()
accepts aFunc<Type, IEnumerable<Service>>
You will also need: