dadhi / DryIoc

DryIoc is fast, small, full-featured IoC Container for .NET
MIT License
982 stars 122 forks source link

Use default constructor if no registration is found #637

Closed mykeels closed 3 months ago

mykeels commented 3 months ago

I have a controller:

public class MyController
{
  public MyController(): this(
    container.Resolve<MyService>()
  ) {}

  public MyController(MyService service)
  { ... }
}

When MyService is never registered, it rightly throws an UnableToResolveUnknownService exception.

However, MyService has a default constructor with empty parameters. Is there a way to get the DryIoc Container to use that when it finds no registrations for the concrete service class?