0

I've setup DI in my Azure Function by using Microsoft.Azure.Functions.Extensions.DependencyInjection and Microsoft.Extensions.DependencyInjection. So this is my startup:

public class Startup : FunctionsStartup
{
    public override void Configure(IFunctionsHostBuilder builder)
    {
        builder.Services.AddTransient<IThingFactory, ThingFactory>();
    }
}

This works fine within the project however I have added a reference to SomeOtherProject.dll (One of my class library projects).

My question is: do i need to setup services for each of the interfaces & implementations from SomeOtherProject that i'll be using?

TimTam
  • 41
  • 1
  • 8
  • yes, and if you are using the same DI configuration in multiple places, you could make a separate project named something like SomeOtherProject.DependencyInjection and put your Configure method there. – Yehor Androsov Mar 03 '20 at 10:19
  • Hello, if the answer is helpful, could you please [accept it as answer](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work?answertab=active#tab-top)? Thanks. – Ivan Glasenberg Mar 25 '20 at 05:58

2 Answers2

1

That depends on you.

If you want to use Dependency Injection of Azure function(it's recommended), you should always setup services for each of the interfaces & implementations from SomeOtherProject.dll.

For example, in SomeOtherProject.dll, you have an interface named IRepository and a class named Repository which implements the interface. And then in the azure function, you reference this SomeOtherProject.dll, you want to use Dependency injection like this sample, you must register them in the Startup class like this builder.Services.AddSingleton<IRepository, Repository>();

But if you don't choose to use Dependency Injection, there is no need to do that, just use them directly.

Ivan Glasenberg
  • 29,865
  • 2
  • 44
  • 60
0

I think it is no need. if you are using dll reference, after adding references,it should be free to use SomeOtherProject's interfaces and implementations.

Cindy Pau
  • 13,085
  • 1
  • 15
  • 27