-
Notifications
You must be signed in to change notification settings - Fork 29
-
If I create a library using Pure.DI for dependency injection, can it then be used in a project not using Pure.DI, but uses the traditional Dependency Injection from Microsoft?
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment 4 replies
-
If I create a library using Pure.DI for dependency injection, can it then be used in a project not using Pure.DI, but uses the traditional Dependency Injection from Microsoft?
Yes your library can of course be used with MS DI.
The easiest way is to simply define some composition roots in your library, make them available from outside. A consumer of your library will be able to register them in the MS DI service collection using extension methods.
Another way, where you yourself will provide a collection of services from your library. Here is an example where all composition roots are added to the MS DI service collection automapically. In this case, you will need to add the Pure.DI.MS package to your library.
You can also provide service providers as in the examples below, but I think this is less suitable for you.
Beta Was this translation helpful? Give feedback.
All reactions
-
Hi, thank you for the reply. The link for the example with adding roots to MS ServiceCollection does not work.
Beta Was this translation helpful? Give feedback.
All reactions
-
Hi, thank you for the reply. The link for the example with adding roots to MS ServiceCollection does not work.
Sorry, I fixed the link
Beta Was this translation helpful? Give feedback.
All reactions
-
Created an example for you
Beta Was this translation helpful? Give feedback.
All reactions
-
But this approach is simpler and better
Beta Was this translation helpful? Give feedback.