dependency-injection

Wrapping Angular components which has Parent/Child relationship

ⅰ亾dé卋堺 提交于 2020-06-27 12:20:03
问题 I'm trying to wrap some third-party components with my own components (All of them are Angular 5 components). When using the third-party component (without wrapping them) I have the following code: <div> <xyz-menubar> <a xyzMenubarItem></a> <a xyzMenubarItem></a> </xyz-menubar> </div> My goal is to wrap these components to have the following code: <div> <app-menu> <app-menu-item></app-menu-item> <app-menu-item></app-menu-item> </app-menu> </div> This is how I coded the wrapped components (xyz

How to register dependency injection with generic types? (.net core)

纵饮孤独 提交于 2020-06-27 10:41:09
问题 I have an asp.net core web app with multiple parameters in appSettings.json file. I didnt' want to have services having IOptions<MyObject> in the constructor. I wanted MyObject in the constructor. So I found the following article: https://weblog.west-wind.com/posts/2017/dec/12/easy-configuration-binding-in-aspnet-core-revisited which is very interesting. But I want to go further. I would like to create an extension method to generate the injection. Here is what I would like to do: using

Why does .NET Core DI container not inject ILogger?

烂漫一生 提交于 2020-06-27 07:20:07
问题 I am trying to get logging up and running in my C# console app based on .NET Core 2.1. I added the following code to my DI declaration: var sc = new ServiceCollection(); sc.AddLogging(builder => { builder.AddFilter("Microsoft", LogLevel.Warning); builder.AddFilter("System", LogLevel.Warning); builder.AddFilter("Program", LogLevel.Warning); builder.AddConsole(); builder.AddEventLog(); }); I am trying to inject the service by using the Interface Microsoft.Extensions.Logging.ILogger in the

Angular DI: Injecting a value token into factory provider

元气小坏坏 提交于 2020-06-25 21:51:50
问题 Is it possible to inject an InjectionToken into a factory provider: Currently, I've coded that: export const HOST_TOKEN = new InjectionToken<string>("host"); let configDataServiceFactory = (userService: UserService, host: string) => { return new Config("host", 8080, userService.getUser(), userService.getPasswd()); }; export let configDataServiceProvider = { provide: CONFIG_API, useFactory: configDataServiceFactory, deps: [UserService, HOST_TOKEN] }; Into my module: @NgModule( providers: [

Use constructor injection for spring ConfigurationProperties subclasses

守給你的承諾、 提交于 2020-06-25 21:50:12
问题 I was looking at this https://www.baeldung.com/configuration-properties-in-spring-boot and was wondering if it was possible to use constructor injection for these in order to enforce some immutability properties. For example would it be possible to do this: @Component @ConfigurationProperties("my-config") public class MyConfig { private final List<String> values; public MyConfig(@Value("${values}") List<String> values) { this.values = ImmutableList.copyOf(values); } } And then in my yml

Use constructor injection for spring ConfigurationProperties subclasses

时间秒杀一切 提交于 2020-06-25 21:49:23
问题 I was looking at this https://www.baeldung.com/configuration-properties-in-spring-boot and was wondering if it was possible to use constructor injection for these in order to enforce some immutability properties. For example would it be possible to do this: @Component @ConfigurationProperties("my-config") public class MyConfig { private final List<String> values; public MyConfig(@Value("${values}") List<String> values) { this.values = ImmutableList.copyOf(values); } } And then in my yml

Use constructor injection for spring ConfigurationProperties subclasses

淺唱寂寞╮ 提交于 2020-06-25 21:48:14
问题 I was looking at this https://www.baeldung.com/configuration-properties-in-spring-boot and was wondering if it was possible to use constructor injection for these in order to enforce some immutability properties. For example would it be possible to do this: @Component @ConfigurationProperties("my-config") public class MyConfig { private final List<String> values; public MyConfig(@Value("${values}") List<String> values) { this.values = ImmutableList.copyOf(values); } } And then in my yml

Symfony passing array of arguments to DI services via yml file

三世轮回 提交于 2020-06-25 10:39:32
问题 I'm using symfony 2.x and I have a class which accept and array of configurations from yml file config.yml services: my_di: class: \MyClass arguments: - param1: 'myvalue' MyClass.php class { public function __construc(array $configs = []) { var_dump($config); } Output (this is working correctly) array (size=1) param1 => 'myvalue' ) But I want to pass one more value to the same array via yml - param2: 'myvalue2' and the exprected output will be array (size=1) param1 => 'myvalue', param2 =>

How to perform async initalization of lazy injection

冷暖自知 提交于 2020-06-25 10:31:17
问题 Let's say we want to inject an object that is expensive to create (let's say it does initialization from a database), so we would typically use some kind of factory or Lazy<T> . However, if we're injecting this object into an MVC or WebApi controller that is using async action methods, we don't want to block these methods on the expensive I/O operation when the Lazy object is initialized, which defeats the purpose of using async. Certainly, I could create an "initlize" method that is async,

ASP.NET Core DbContext injection

会有一股神秘感。 提交于 2020-06-25 09:02:28
问题 I have a ConfigurationDbContext that I am trying to use. It has multiple parameters, DbContextOptions and ConfigurationStoreOptions . How can I add this DbContext to my services in ASP.NET Core? I have attempted the following in my Startup.cs: ConfigureServices .... services.AddDbContext<ConfigurationDbContext>(BuildDbContext(connString)); .... private ConfigurationDbContext BuildDbContext(string connString) { var builder = new DbContextOptionsBuilder<ConfigurationDbContext>(); builder