Saturday, February 22, 2020

Dynamic dependency injection .NET Core WebAPI

It is being a long time after my last blog post here. I already moved to .NET Core from .NET Framework almost two years ago. And I must say it has been made my life easier. Well I can say I am intrigued with in build dependency injection. Recently I got a requirement that needs two different implementations for single interface.

Classes : ProcessExcelFiles.cs
               ProcessCsvFiles.cs

Interface : IFileUploadContentProcess.cs

Purpose of this two classes are process uploaded xlsx file or csv file.

First register class files as your desired way.

Then use a lambda function to parameterize interfaces to implementation register.

How to use: