Injecting generic services

0
0

Using microsoft’s DI we are able to inject a generic service as follows:
builder.Services.AddScoped(typeof(DBConnection<>));

this allows us to inject any DBConnection<T> without actually registering a DBConnection<T> for each T.

 

unfortunately I can’t find how to do it using wisej DI.

 

Any advise?

Best regards,

Ali

  • You must to post comments
0
0

To update (late) this thread, generic services are supported since 3.5.4:

 

// Register generic service
Application.Services.AddService(typeof(DBConnection<>));

// Request service
var dbTrucks = Application.Services.GetService<DBConnection<Truck>>);
var dbEmloyees = Application.Services.GetService<DBConnection<Employee>>);

 

  • You must to post comments
0
0

Hi Ali,

did you check out our documentation at

https://docs.wisej.com/docs/concepts/dependency-injection

Best regards
Frank

  • Ali Badran
    Yes, I’m following the documentation, I didn’t find any option to inject a generic service as I mentioned in my question. As a workaround I’m currently using MS DI.
  • Luca (ITG)
    Correct. It’s not supported but you can use any .NET container. If you like the MS one that’s a good solution.
  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.