How to Register Open Generic in .NET Core Dependency Injection

Muhammad Waseem
Dec 17, 2022

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.

1. For .NET 3.1 register in Configure Services in ๐’๐ญ๐ซ๐š๐ญ๐ฎ๐ฉ.๐œ๐ฌ

2. For latest versions of .NET(6.0 ,7.0) register in ๐๐ซ๐จ๐ ๐ซ๐š๐ฆ.๐œ๐ฌ

Help the author in growing

  1. Subscribe my Weekly .NET Newsletter of C#/.NET
  2. Follow me OR Clap at least 50 times
  3. Get exclusive .NET Questions & Answers by becoming a Patreon

--

--