Static class or Singleton for utility class in .NET Core with DI

459 Views Asked by At

I'm migrating a utility class to a .NET Core class library.

At first I thought I can simply make a static class for this but I have a dependency on IConfiguration so I'm not sure how to proceed with this.

What is the best practice for this situation?

Should I use a class and use constructor injection and then add it in ConfigureServices?
Should I use a static class and use method injection?

Or I shouldn't even come across this type of issue :-?
I would guess that the first version is nicer.
Sorry if this is a dumb question, I'm a bit confused for the options I have.

Thank you!

0

There are 0 best solutions below