question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Register open generics in ASP.NET Core

See original GitHub issue

Given the following:

public class Foo : IFoo {
  ...
}

public class FooValidator : AbstractValidator<IFoo> {
  ...
}

It would be nice to be able to resolve IValidator<Foo> from the ASP.NET Core DI Container.

I know the built-in DI container does not support open generics out of the box, so one would have to scan the assembly and explicitly register the validator for all concrete implementations of IFoo.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
JeremySkinnercommented, Oct 23, 2017

Yep, can definitely look at doing that for a future version

1reaction
JeremySkinnercommented, Oct 23, 2017

The simplest thing is probably just to register these types with the container directly manually rather than relying on FV’s built in AssemblyScanner

Read more comments on GitHub >

github_iconTop Results From Across the Web

Registering Open Generics in ASPNET Core Dependency ...
NET Core startup, there is a simple way to do so. ... Registering Open Generics in ASPNET Core Dependency Injection.
Read more >
ASP.NET Core dependency injection: Registering open ...
A really interesting trick you can do with the ASP.NET core dependency injection is that you can register an open generic type.
Read more >
How to register dependency injection with generic types? ...
I have an asp.net core web app with multiple parameters in appSettings.json file. I didnt' want to have services having IOptions<MyObject> in ...
Read more >
Constrained Open Generics Support Merged in .NET Core ...
The built-in container is a conforming container - that is, it provides some default behaviors that ASP.NET Core requires, and if you want...
Read more >
How to Register Open Generic in .NET Core Dependency ...
In this topic we would cover. How to create a Open Generic; Right way to register Dependency Injection. If you have a generic...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found