Pure.DI icon indicating copy to clipboard operation
Pure.DI copied to clipboard

Ability to register composition roots with fewer API calls

Open NikolayPianikov opened this issue 4 months ago • 0 comments

Right now:

DI.Setup(nameof(Composition))
  .Bind<IService>().To<Service>()
  .Bind<IService>("Other").To<OtherService>()
  .Root<IService>("MyRoot")
  .Root<IService>("SomeOtherService", "Other");

An API such as this is proposed:

DI.Setup(nameof(Composition))
  .RootBind<IService>("MyRoot").To<Service>()
  .RootBind<IService>("SomeOtherService", "Other").To<OtherService>()

Thus we could add a new API method to IConfiguration like:

IBinding RootBind<T>(string name = "", object tag = null, RootKinds kind = RootKinds.Default);

For integration tests and local debugging, you can use this project.

Major changes are likely to be here.

We also need an example in the documentation. It can be done here.

NikolayPianikov avatar Mar 01 '24 07:03 NikolayPianikov