dependency-injection

How to inject or use IConfiguration in Azure Function V3 with Dependency Injection when configuring a service

巧了我就是萌 提交于 2021-01-20 15:57:32
问题 Normally in a .NET Core project I would create a 'boostrap' class to configure my service along with the DI registration commands. This is usually an extension method of IServiceCollection where I can call a method like .AddCosmosDbService and everything necessary is 'self-contained' in the static class containing that method. The key though is that the method gets an IConfiguration from the Startup class. I've worked with DI in Azure Functions in past but haven't come across this specific

How to inject or use IConfiguration in Azure Function V3 with Dependency Injection when configuring a service

你离开我真会死。 提交于 2021-01-20 15:56:42
问题 Normally in a .NET Core project I would create a 'boostrap' class to configure my service along with the DI registration commands. This is usually an extension method of IServiceCollection where I can call a method like .AddCosmosDbService and everything necessary is 'self-contained' in the static class containing that method. The key though is that the method gets an IConfiguration from the Startup class. I've worked with DI in Azure Functions in past but haven't come across this specific

What is a DI Container?

妖精的绣舞 提交于 2021-01-20 15:51:30
问题 I am watching this course video about dependency injection and the instructor talked about di-container but did not explain in detail, now I read some articles and I want to confirm that now I am getting this right. Below is simple program and my question is, Is Program class below is kind of simplest di-container? if not how would simple di-container would be like interface Implementable { void doSmth(); } class A implements Implementable { @Override public void doSmth() { } } class B {

Is there a robust way to register dependencies in ASP.NET Core 3.1 beside adding everything into Startup class?

大城市里の小女人 提交于 2021-01-18 03:53:38
问题 I have an ASP.NET Core 3.1 project. Typically, I register any dependency using the ConfigureServices() method in the Startup.cs class. But, I find myself having to register lots of dependencies and the ConfigureServices() looks huge! I know I can probably create an extension method of a static method and call it from the ConfigureService()` class, but wondering if there is a better way. If there a way to register dependencies in the IoC container without having to define them one at a time

Is there a robust way to register dependencies in ASP.NET Core 3.1 beside adding everything into Startup class?

这一生的挚爱 提交于 2021-01-18 03:52:19
问题 I have an ASP.NET Core 3.1 project. Typically, I register any dependency using the ConfigureServices() method in the Startup.cs class. But, I find myself having to register lots of dependencies and the ConfigureServices() looks huge! I know I can probably create an extension method of a static method and call it from the ConfigureService()` class, but wondering if there is a better way. If there a way to register dependencies in the IoC container without having to define them one at a time

Spring autowired collection of qualified beans

谁都会走 提交于 2021-01-06 10:45:57
问题 I have some Spring @Components with @Qualifier annotations, let's say it's in example "A" and "B". I want to inject them (using only annotations) into List. How can I do that ? @Component public class WhatIHave { @Autowired @Qualifier("A") private MyType firstBean; @Autowired @Qualifier("B") private MyType secondBean; .... } @Component public class WhatIWantToHave { @Autowired @Qualifier("A", "B") //something like that private List<MyType> beans; ... } Do I need to make it in @Configuration

Best practice injecting service into another service [closed]

China☆狼群 提交于 2021-01-05 08:53:14
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed last month . Improve this question We suppose that I have Two Entity ( Subscription and Application ) and for each one his Repository layer named ( SubscriptionRepository and ApplicationRepository ) and two Service for each one ( ISubscriptionService and IApplicationService ) In some case,

.NET Core - Changing dependency in Controller

徘徊边缘 提交于 2021-01-04 10:34:45
问题 I am working on an web application (.net core 2.2) and trying to replace existing dependency over an querystring parameter in controller. I know, it is possible to replace dependency inside Startup.cs (ConfigureServices(IServiceCollection services) method). But problem is I cant access "IServiceCollection " in controller. Do you guys have an idea how to achive it? This is the way to replace dependency in Startup. "ServiceCollectionDescriptorExtensions" has "Replace" method. services.Replace

Binding classes with property injection to kernel in inversify

拥有回忆 提交于 2021-01-04 05:33:49
问题 I am trying to achieve dependency injection on my node project via inversify. I have a kernel config like this: inversify.config.ts import "reflect-metadata"; import {Kernel, interfaces} from "inversify"; import {Config} from "./config"; import {Collection} from "./collection"; let kernel = new Kernel(); kernel.bind<Config>("Config").to(Config).inSingletonScope(); // kernel.bind<interfaces.Newable<Collection>>("Collection").toConstructor<Collection>(Collection); // it works without the line

How to instantiate Angular components with parameters?

廉价感情. 提交于 2021-01-03 07:02:21
问题 I've been trying to instantiate components by passing parameters like nameFilter = new FilterComponent("Name"); but I'm getting this error: NullInjectorError: No provider for String! I believe dependency injection causes this as I don't get any errors if I don't inject anything to component. So what exactly causes this and how can I fix it? Here's the component code import { Component, OnInit, Inject } from '@angular/core'; @Component({ selector: 'app-filter', templateUrl: './filter.component