Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Library using Pure.DI consumed by MS DI #79

Unanswered
bstordrup asked this question in Q&A
Discussion options

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?

You must be logged in to vote

Replies: 1 comment 4 replies

Comment options

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.

You must be logged in to vote
4 replies
Comment options

Hi, thank you for the reply. The link for the example with adding roots to MS ServiceCollection does not work.

Comment options

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

Comment options

Created an example for you

Comment options

But this approach is simpler and better

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /