How to Register Open Generics i n .NET Core Dependency InjectionsteemCreated with Sketch.

in #dotnetcore2 years ago

In this topic we would cover

  1. How to create a Open Generic
  2. Right way to register Dependency Injection

If you have a generic interface and its generic implementation like we mostly do when we make a generic repository for CRUD operations and you want to register its dependency injection at startup, then there is a simple way of registering the DI.

DIofGenerics.png

  1. For .NET 3.1 register in ConfigureServices in 𝐒𝐭𝐫𝐚𝐭𝐮𝐩.𝐜𝐬

  2. For latest versions of .NET(6.0 ,7.0) register in 𝐏𝐫𝐨𝐠𝐫𝐚𝐦.𝐜𝐬

#dotnetcore #dependency #dependencyinjection #entityframework #csharp #dotnet6