When Verify()
my container I get the following error:
An unhandled exception of type 'System.InvalidOperationException' occurred in SimpleInjector.dll
Additional information: The configuration is invalid. Creating the instance for type ICommunicationApiFacade failed. The constructor of type CommunicationApiFacade contains the parameter with name 'getLogger' and type
Func<Object, ILogger>
that is not registered. Please ensureFunc<Object, ILogger>
is registered, or change the constructor of CommunicationApiFacade.
This is my IocConfig class
container.RegisterSingleton<Func<object, ILogger>>(
x => LogManager.GetLogger(x.GetType().FullName));
container.RegisterSingleton<Func<string, ICommunicationClient>>(
tenant => new CommunicationClient(
new Uri(configuration.AppSettings["communication_api." + tenant]),
new TenantClientConfiguration(tenant)));
container.RegisterSingleton<ICommunicationApiFacade, CommunicationApiFacade>();
This is my CommunicationApiFacade class
internal class CommunicationApiFacade : ICommunicationApiFacade
{
private readonly ILogger _logger;
private readonly Func<string, ICommunicationClient> _communicationFactory;
public CommunicationApiFacade(Func<object, ILogger> getLogger,
Func<string, ICommunicationClient> communicationFactory)
{
_logger = getLogger(this);
_communicationFactory = communicationFactory;
}
...
}
Interestingly, this logger is being used in other places. By removing any appearance of ILogger from CommunicationApiFacade all works fine.