dependency-injection

Typhoon : Obtain a Typhoon-built instance of a class without depending on Typhoon

我们两清 提交于 2020-01-25 10:58:06
问题 With Typhoon storyboard integration, all that is necessary for dependency injection is to use auto-injection macros or assembly methods on the class to be injected. However elsewhere, its necessary to ask Typhoon to build an instance for us. Is there a way to obtain an instance, without having my class depend on Typhoon? 回答1: Yes, in the spirit of dependency injection, Typhoon is designed so that its not necessary for any user classes to have a direct dependency on Typhoon. Let's say you wish

DI Registration service type .net core 3.0

不打扰是莪最后的温柔 提交于 2020-01-25 08:34:07
问题 I have one n-tier layered app and in Infrastructure module where I'm trying to develop sending email for confirmation an user, I'm getting an error. No service for type 'IMS.Infrastructure.Helpers.CustomEmailConfirmationTokenProvider`1[Microsoft.AspNetCore.Identity.IdentityUser]' has been registered. From code what I had did is next: public class CustomEmailConfirmationTokenProvider<TUser> : DataProtectorTokenProvider<TUser> where TUser : class { public CustomEmailConfirmationTokenProvider

Prototype scope bean in controller returns the same instance - Spring Boot

陌路散爱 提交于 2020-01-25 07:56:44
问题 I have a contoller which is defined as below: @RestController public class DemoController { @Autowired PrototypeBean proto; @Autowired SingletonBean single; @GetMapping("/test") public String test() { System.out.println(proto.hashCode() + " "+ single.hashCode()); System.out.println(proto.getCounter()); return "Hello World"; } } And i have defined prototype bean as below: @Component @Scope(value= ConfigurableBeanFactory.SCOPE_PROTOTYPE) public class PrototypeBean { static int i = 0; public int

Why does angular project fail AoT build when injecting Interfaces?

江枫思渺然 提交于 2020-01-24 21:55:32
问题 Ok, sorry if the title was not clear. I'm trying to implement a pattern involving injecting interfaces. It works perfectly in JIT but not in AoT. I was hoping to get an explanation of why this doesn't work and hopefully some suggestions to make it work. Here's a simplified example of the pattern. data-manager.interface.ts @Injectable() export class DataManager implements DataManager {} export interface DataManager { getData(): Promise<Array>; ... } ^Declares Interface dashboard.service.ts

Type script - angular : static injector error

霸气de小男生 提交于 2020-01-24 19:26:19
问题 Hi i am trying to use socket.io in my angular project. there are three files which i am going to show which are component file and one service file and one module file. when ever i use service in my component file i get the static injector error. which is: Error: StaticInjectorError(AppModule)[AppComponent -> WrappedSocket]: StaticInjectorError(Platform: core)[AppComponent -> WrappedSocket]: NullInjectorError: No provider for WrappedSocket! Here is the Component file: import { Component }

Type script - angular : static injector error

白昼怎懂夜的黑 提交于 2020-01-24 19:26:04
问题 Hi i am trying to use socket.io in my angular project. there are three files which i am going to show which are component file and one service file and one module file. when ever i use service in my component file i get the static injector error. which is: Error: StaticInjectorError(AppModule)[AppComponent -> WrappedSocket]: StaticInjectorError(Platform: core)[AppComponent -> WrappedSocket]: NullInjectorError: No provider for WrappedSocket! Here is the Component file: import { Component }

Spring, using new ClassPathXmlApplicationContext and getting error being unable to find applicationContext.xml and others?

拈花ヽ惹草 提交于 2020-01-24 13:58:07
问题 I am trying to follow this tutorial: http://www.vogella.de/articles/SpringDependencyInjection/article.html to use annotation dependency injection in my application. I set up the bean, etc like in the tutorial and then am trying to get an instance of the bean within my MainController class (a controller class that handles generating a specific page for my spring web mvc app).. I keep getting SEVERE: Servlet.service() for servlet spring threw exception java.io.FileNotFoundException: class path

Logging to Console with DI in C#

放肆的年华 提交于 2020-01-24 11:15:37
问题 in this short sample, if I keep just the .AddConsole() in ConfigureServices nothing gets logged to console regardless of the LogLevel, but if I add .AddConsole().AddDebug() all messages get logged to Console 3 times! What am I missing? Thanks! namespace samples { using System; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; public class Program { public static void Main(string[] args) { var serviceCollection = new ServiceCollection(); ConfigureServices

Unit testing and mocking a service with DI

隐身守侯 提交于 2020-01-24 10:01:05
问题 I have been struggling with this for a while, and I'm hoping someone can help. I have a component that uses a service to get data. I am attempting to add unit tests to it. My problem is that the tests always fail with "Error: No provider for Http". Here is my code: Service: import { Injectable } from '@angular/core'; import { Http } from '@angular/http'; import { Observable } from 'rxjs/Rx'; import 'rxjs/add/operator/map'; import { Contact } from './contact.model'; @Injectable() export class

What is wrong in my way of explainning DI and IoC?

江枫思渺然 提交于 2020-01-24 10:00:48
问题 Yesterday during an interview I was asked what DI and IoC in spring were. My reply was: when a class(A) extends abstract class(B) or implements interface(B) or create a object of class(B) of any class in it, then A is said said to be dependent on B . Injecting this dependency, i.e. injecting the object in costructor or in setter method is called DI and in this process control over creating object goes to the "outside world" like XML configuration, this inversion of control is IoC. DI is not