FoundatioFx / Foundatio

Pluggable foundation blocks for building distributed apps.
Apache License 2.0
1.96k stars 243 forks source link

Examples for DependencyInjection #288

Closed U52284 closed 1 year ago

U52284 commented 1 year ago

I'm currently trying to integrate IFileStorage but I'm missing a good example on how to use it in DI. Is there an out of the box extension to register one or another implementation of the interface? I have an enumeration of the providers I want to provide and register one or the other. Also to make use of the scoped file storage in combination with the providers.

Or do I have to do all myself? Just dont want to wast time on something already existing.

Thanks in advance

ejsmith commented 1 year ago

If you are wanting multiple variations of IFileStorage, you'd need to handle that yourself. What we've typically done is create a derived interface like IMyFileStorage that inherited IFileStorage and then you'll have to derived from the implementation class and implement that interface as well.

U52284 commented 1 year ago

Thought about that. But also I was sure I'm not the first one encountering that one or maybe I havent seen a build in mechanism that is already prepared for that. It seems this would be a very good thing beeing available out of the box.

ejsmith commented 1 year ago

There isn’t really a great solution to this. It’s really a named instance DI issue which is a feature getting built into .NET 8. If you have other ideas, feel free to discuss or create a PR.

U52284 commented 1 year ago

I will check if I can setup something in the next week or so. For now thats enough input for me thank you.