kontent-ai / delivery-sdk-net

Kontent.ai Delivery .NET SDK
https://www.nuget.org/packages/Kontent.Ai.Delivery
MIT License
32 stars 42 forks source link

Introduce ILoggerFactory to all possible ways to create Delivery Client #373

Closed Simply007 closed 1 year ago

Simply007 commented 1 year ago

Brief bug description

Related to #358

Repro steps

i.e. DeliveryClientFactory.Create is missing these options

Expected behavior

dzmitryk-kontent-ai commented 1 year ago

I reviewed the code and from my perspective we cover all existing scenarios

  1. DeliveryClientFactory.Create method is used only in obsolete NamedDeliveryClientFactory. I wouldn't change anything there, as we don't recommend to use this approach anymore
  2. In the code, as well as in our documentation I can see 2 ways how to create DeliveryClient https://github.com/kontent-ai/delivery-sdk-net/blob/master/docs/configuration/dependency-injection.md 2.1 using DI - we can register ILoggerFactory using services.AddSingleton<IloggerFactory, YourLoggerFactory>() 2.2 using DeliveryClientBuilder - we can use WithLoggerFactory() method
  3. When we register DeliveryClientCache, we also have 2 possibilities to do it - https://github.com/kontent-ai/delivery-sdk-net/blob/master/docs/retrieving-data/caching.md 3.1 using DI. The approach is the same as above - we should add ILoggerFactory implemetation to DI 3.2 we can create CacheManager using CacheManagerFactory.Create method, which has optional loggerFactory parameter
  4. If we want to have "Multiple Delivery clients", the recommended approach is to use AddMultipleDeliveryClientFactory method - https://github.com/kontent-ai/delivery-sdk-net/blob/master/docs/configuration/multiple-delivery-clients.md 4.1 we can create regular DeliveryClient using AddDeliveryClient method. It has optionalConfig delegat parameter and we can call WithLoggerFactory method there. Each registered DeliveryClient will have its own ILoggerFactory implementation 4.2 DeliveryClientCache can be added using AddDeliveryClientCache method. We can register ILoggerFactory implemetation for whole DeliveryClientCache the same as it described in 4.1. Nevertheless, due to the fact that CacheManager instance is created using CacheManagerFactory.Create method, it's necessary to register ILoggerFactory instance to CacheManager separately using its optional parameter loggerFactory. It doesn't seem to be the best solution, but this is the price for CacheManager is created directly without DI's usage.
Simply007 commented 1 year ago

Thx - so we can close this issue.