2

I'm using LightInject as a IoC container for my class library project. As these projects type do not have any entry point or startup methods where i can write the code for registering the dependencies. I want to implement something auto registration , so any client which consumes my library, and which has dependencies on it, they should all get auto resolved without client explicitly calling the Registration method.

Also the LightInject should be abstracted from the client. It should never know how the objects are created / destroyed internally within the class library.

MAQ
  • 443
  • 7
  • 15

1 Answers1

1

Implement the ICompositionRoot interface and the Compose method will be executed the first time an "unknown" service is requested. Another approach is to put the registration in a static constructor somewhere.

seesharper
  • 3,249
  • 1
  • 19
  • 23
  • can you share an example of such implementation? I'm interested in knowing about how dependencies are provided to consumers. using chain of constructor like stackoverflow.com/questions/30207405/… or any auto resolution method is there for constructor inject in entry point. – VISHMAY Feb 04 '19 at 07:33