dependency-injection

Serilog DI in ASP.NET Core, which ILogger interface to inject?

江枫思渺然 提交于 2020-07-22 14:11:31
问题 Context I've successfully configured Serilog in my ASP.NET Core application, only the DI part remains. Question Now I have two ILogger interfaces, one is Serilog.ILogger the other is Microsoft.Extensions.Logging.ILogger . Both works based on my Serilog config, and I do not know which to use? (I mean, after Serilog config in place Microsoft.Extensions.Logging.ILogger also correctly logging through Serilog, so my config is honored) In case Microsoft.Extensions.Logging.ILogger I do know how to

Error [Dagger/MissingBinding] androidx.lifecycle.ViewModelProvider.Factory cannot be provided without an @Provides-annotated method

淺唱寂寞╮ 提交于 2020-07-21 07:11:10
问题 I am facing an issue while implementing MultiBinding using dagger 2.2. I am using dagger with MVVM architecture. I have injected the ViewModelProvideFactory constructor and binds the dependency from module. I have followed the tutorial of Mitch from youtube https://www.youtube.com/watch?v=DToD1W9WdsE&list=PLgCYzUzKIBE8AOAspC3DHoBNZIBHbIOsC&index=13 I have searched on these links for the solutions but still facing the same issue. Dagger2: ViewModel cannot be provided without an @Provides

Get DataProtectionProvider in MVC 5 for dependecy injection correctly

不问归期 提交于 2020-07-20 17:19:26
问题 When trying to create a DataProtectionProvider manually I have stumbled upon the Microsoft documenation to DpapiDataProtectionProvider which says: Used to provide the data protection services that are derived from the Data Protection API. It is the best choice of data protection when you application is not hosted by ASP.NET and all processes are running as the same domain identity. A question suddenly arises: What is the best choice when your application IS hosted by ASP.NET? Searching

Get DataProtectionProvider in MVC 5 for dependecy injection correctly

假装没事ソ 提交于 2020-07-20 17:19:10
问题 When trying to create a DataProtectionProvider manually I have stumbled upon the Microsoft documenation to DpapiDataProtectionProvider which says: Used to provide the data protection services that are derived from the Data Protection API. It is the best choice of data protection when you application is not hosted by ASP.NET and all processes are running as the same domain identity. A question suddenly arises: What is the best choice when your application IS hosted by ASP.NET? Searching

Cannot resolve scoped service from root provider. ASP.NET MVC app App

我的未来我决定 提交于 2020-07-19 07:24:40
问题 I am doing Store application with Pro ASP.NET Core MVC 6th Edition by Adam Freeman. The example in book is made in Core 1.0, and I am using Core 3.0. I get error as below, while trying to seed data to my database (entityFramework). System.InvalidOperationException: 'Cannot resolve scoped service 'BookStore.Models.ApplicationDbContext' from root provider.' Below is my code: public class SeedData { public static void EnsurePopulated(IApplicationBuilder app) { ApplicationDbContext context = app

Cannot resolve scoped service from root provider. ASP.NET MVC app App

假如想象 提交于 2020-07-19 07:23:11
问题 I am doing Store application with Pro ASP.NET Core MVC 6th Edition by Adam Freeman. The example in book is made in Core 1.0, and I am using Core 3.0. I get error as below, while trying to seed data to my database (entityFramework). System.InvalidOperationException: 'Cannot resolve scoped service 'BookStore.Models.ApplicationDbContext' from root provider.' Below is my code: public class SeedData { public static void EnsurePopulated(IApplicationBuilder app) { ApplicationDbContext context = app

Symfony 4.1 components - Dependency Injection issues

三世轮回 提交于 2020-07-19 06:14:27
问题 I'm refactoring old application in PHP. I'm trying to use Symphony dependency injection component to inject services into controllers (or other services), but I don't know how to achieve this, because symphony documentation is more prepared for using framework, than framework components. I already have my own Kernel, Container that contains all services and controllers (controllers are registered as services already). My controllers extending AbstractController from symfony/frameworkbundle .

Symfony4 use external class library as a service

两盒软妹~` 提交于 2020-07-18 10:43:14
问题 I have a little external library that expose many classes. Into my symfony4 project I would like to declare my class from vendor, as a service with autowire and public. So I have include my library with composer and add psr configuration like this into composer.json: "autoload": { "psr-4": { "App\\": "src/", "ExternalLibrary\\": "vendor/external-library/api/src/" } } After that I have tried to change my services.yaml into symfony like this: ExternalLibrary\: resource: '../vendor/external

Symfony4 use external class library as a service

佐手、 提交于 2020-07-18 10:42:52
问题 I have a little external library that expose many classes. Into my symfony4 project I would like to declare my class from vendor, as a service with autowire and public. So I have include my library with composer and add psr configuration like this into composer.json: "autoload": { "psr-4": { "App\\": "src/", "ExternalLibrary\\": "vendor/external-library/api/src/" } } After that I have tried to change my services.yaml into symfony like this: ExternalLibrary\: resource: '../vendor/external

How to inject(autowired) beans to map with enum as map key in spring?

不打扰是莪最后的温柔 提交于 2020-07-18 07:47:20
问题 I've learned that in spring, i can autowire/inject into Map<String, SomeBeanInterface> by configured name like below: public interface DummyInterface{ } @Component("impl1") public class Impl1 implement DummyInterface{ } @Component("impl2") public class Impl2 implement DummyInterface{ } public class SomeUsage{ @Autowired private Map<String, DummyInterface> mapping; // ... } and retrieve the Component by string as key like: SomeUsage use = new SomeUsage(); DummyInterface dummy = use.getMapping(