I need to use Deckor.NET https://github.com/lawrence-laz/Decor.NET/tree/master to add attribute on method.
Application is created in .NET and using Dependency injection with Transient and Func.
When service is registered with Singletion scope and without Scope there is no error:
services.AddDecor().AddTransient<CacheDecorator>().AddTransient<CacheTestBLL>().Decorated();
When I add service with Transient scope and Func I cannot get instance of service:
services.AddDecor();
services.AddSingleton<CacheDecorator>();
services.AddSingleton<CompanyTest1BLL>().Decorated();
services.AddSingleton<CompanyTest2BLL>().Decorated();
services.AddTransient<Func<Account, ICompany1BLL>>(serviceProvider => account =>
{
switch (account)
{
case Account.Company1:
return serviceProvider.GetService<CompanyTest1BLL>();
case Account.Company2:
return serviceProvider.GetService<CompanyTest2BLL>(); <-- error
default:
throw new Exception("Company not found.");
}
});
I get error when application calls GetService() method:
MissingMethodException: Constructor on type 'Castle.Proxies.CompanyTest2BLLProxy' not found.
Decor.NET uses internally Castle.
Probably I should GetService by decorated type but I can’t find what it is.