简体   繁体   中英

.NET Core - How is ILoggerFactory injected?

I'm a bit confused about the use of the ILoggerFactory interface in .NET Core.

In my integration test I need to new up a MemcachedClientConfiguration object, which insists on a ILoggerFactory parameter.

In the articles and examples I've seen, it looks like ILoggerFactory is automatically injected as a dependency in .NET core. But how would I know what implementation of ILoggerFactory to new up in my integration test?

Clearly there's something missing in my understanding, as whenever I've injected interfaces before I've always had to declare and register them in my IOC class (coming from .NET framework). If I wanted to use a third party logging library like log4net, how would I feed this in to MemcachedClientConfiguration?

As mentioned the comments, this specific case may not require you to provide a concrete implementation of an ILoggerFactory . A simple mock can be enough for the integration tests.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM