dependency-injection

Injection in Angular 2. How does it work?

随声附和 提交于 2021-02-19 05:40:06
问题 I've been learning Angular 2 for a few days now. When I read about the Injectable() concept in Angular 2 and try to apply the tutorial's example code in this link : Angular 2 - Dependency Injection, I get a problem. They said I need to put the annotation @Injectable() on top of the class so that the other classes can inject, like: import { Injectable } from '@angular/core'; @Injectable() export class appService { getApp(): string { return "Hello world"; } } The problem is that when I drop

Register collection of services in MVC Core DI

流过昼夜 提交于 2021-02-19 04:22:18
问题 I`ve got simple class with strategies. public class LinkQualifier : ILinkQualifier { private readonly IEnumerable<IQualifier> _qualifiers; public LinkQualifier(IEnumerable<IQualifier> qualifiers) { _qualifiers = qualifiers; } public IQualifier Qualify(Uri uri) { return _qualifiers.FirstOrDefault(q => q.CanQualify(uri)); } } How i can register it in MVC core DI container? I invented something like this: services.AddTransient<ILinkQualifier, LinkQualifier>((ctx => { var qualifiers = new List

Dependency Injection with options pattern

此生再无相见时 提交于 2021-02-19 01:36:09
问题 I'm trying to load some settings from the appsettings file and I've got a small issue with the way lists are loaded when using the options pattern. Suppose I've got the following classes (for loading the settings): public class Application { public string Name { get; set; } = ""; public IEnumerable<string> Roles { get; set; } = new[] {""}; public Application ToApplicationWithoutPass() => new Application { Name = Name, Username = Username, Roles = Roles.ToList() }; } public class Applications

Get session service using IServiceProvider

♀尐吖头ヾ 提交于 2021-02-18 22:42:50
问题 I need to access session variable in ConfigureService method in ASP.NET Core 1.0 using IServiceProvider. I have a service that is initialized with delegate/lambda expression that can return value from any place. In this context this lambda expression argument should return value from session once called. Here is example code: public void ConfigureServices(IServiceCollection services) { services.AddTransient<IMyService>(serviceProvider => { return new MyService(() => { var session =

Get session service using IServiceProvider

旧街凉风 提交于 2021-02-18 22:42:35
问题 I need to access session variable in ConfigureService method in ASP.NET Core 1.0 using IServiceProvider. I have a service that is initialized with delegate/lambda expression that can return value from any place. In this context this lambda expression argument should return value from session once called. Here is example code: public void ConfigureServices(IServiceCollection services) { services.AddTransient<IMyService>(serviceProvider => { return new MyService(() => { var session =

Dependency injection with unity in a class library project

笑着哭i 提交于 2021-02-18 17:35:12
问题 I am new with the dependency injection pattern. I'm a little confused about few things. Scenario: I have a class library project called 'MailCore'. This project has interfaces and classes that perform all email sending stuff. I have an MVC project called 'The site'. It uses the 'MailCore' project to send email. I have Unity in this project and the UnityContainer is registered and things are working fine. I also have another class library library project called 'SiteRepo'. Sometimes, to

How does spring achieve dependency injection at runtime?

百般思念 提交于 2021-02-18 11:36:30
问题 Does anyone know what technique spring uses to achieve dependency injection at runtime? Does it simply use aspects (AOP) or is it something more complicated? 回答1: Spring does a lot of things, but dependency injection itself is actually a surprisingly simple mechanism. It starts with having a registry for classes that are available for injection. Classes that are added to this registry are examined using reflection. A DI framework will look for relevant annotations and constructors to

How does spring achieve dependency injection at runtime?

百般思念 提交于 2021-02-18 11:36:03
问题 Does anyone know what technique spring uses to achieve dependency injection at runtime? Does it simply use aspects (AOP) or is it something more complicated? 回答1: Spring does a lot of things, but dependency injection itself is actually a surprisingly simple mechanism. It starts with having a registry for classes that are available for injection. Classes that are added to this registry are examined using reflection. A DI framework will look for relevant annotations and constructors to

Custom WebSecurityConfigurerAdapter

陌路散爱 提交于 2021-02-17 20:27:20
问题 I have this problem implementing a custom login authentication using SpringBoot and SpringBoot-Security. I made a Bitbucket repository as reference for this thread (within CustomSecuringWeb branch). Before anything else, most of the comments here follows the Securing a Web Application tutorial. The thing is, I was curious as how could the authentication data is now from the database instead of just memory data (which is very common in production line applications). Throughout the process I

How to use Dagger in Java library module in Android Studio?

ぐ巨炮叔叔 提交于 2021-02-17 01:58:23
问题 I'm using Dagger in a Java library module in an Android Studio project and here's what my build.gradle for the module looks like: apply plugin: 'java-library' dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.google.dagger:dagger:2.24' annotationProcessor 'com.google.dagger:dagger-compiler:2.24' } sourceCompatibility = "7" targetCompatibility = "7" I can see that the Dagger is properly generating implementations and they are present in build/generated