Home > Net >  How is a class name used as a generic parameter?
How is a class name used as a generic parameter?

Time:02-10

I understand generics in C# and they are used to keep things strongly typed. I'm using Entity Framework and I'm seeing the < > syntax used, but it seems to be naming a parameter for a method as opposed to a type.
For example

services.AddDbContext<MyDbContext>(options => options.UseSqlServer(...));

MyDbContext is not a type, it's a class needed to link the DB and Models together. But how is the syntax used here? Shouldn't it be....

 services.AddDbContext(MyDbContext);

Clearly I'm not understanding something about syntax here.

CodePudding user response:

  •  Tags:  
  • Related