alerya
alerya

Reputation: 3175

.net core injection Factory

I am trying to make a factory in net Core. And completely get stacked.

How to make factory pattern using Microsoft Dependency Injection library for .net core?

Any hints?

Upvotes: 0

Views: 653

Answers (1)

calingasan
calingasan

Reputation: 1005

Check out my answer here

https://stackoverflow.com/a/44793349/4335854

DI is done through the ServiceCollection where you can only have one implementation per interface so doing a factory pattern directly on the service collection may not work because it does not support dynamic creation of the interface implementation.

What I did in my answer is created an injectable implementation of a factory that may meet the same requirements as a factory of injectable implementations

Upvotes: 1

Related Questions