dependency-injection

Resolve dependencies for authentication event handler through DI

蹲街弑〆低调 提交于 2021-01-23 06:17:49
问题 I use JWT bearer tokens to protect my ASP.NET Core 2.1 web API. During ConfigureServices , I setup the authentication, and tie in a JwtBeaererEvents object via options for additional processing. I'd like this object to be part of the DI container but I'm not sure how to do that. For now, I have to create instances and pass it through the constructor (anti-pattern). But this is going to create a chicken and an egg scenario: /* HACK */ var sp = services.BuildServiceProvider(); services

@Autowired not working in inner class

安稳与你 提交于 2021-01-22 19:41:35
问题 I have a class being @Autowired in inner class. But while executing it throws a Null Pointer Exception, whereas it works fine when Autowired in outer class class outer { ... class inner { @Autowired private var somevar; private process () { somevar.someMethod(); } } Any idea why this is not working? somevar.someMethod(); line is generating NPE. 回答1: Is there any reason why the outer class manages the inner instance creation? For example does the inner object need a reference to the outer one?

@Autowired not working in inner class

房东的猫 提交于 2021-01-22 19:38:12
问题 I have a class being @Autowired in inner class. But while executing it throws a Null Pointer Exception, whereas it works fine when Autowired in outer class class outer { ... class inner { @Autowired private var somevar; private process () { somevar.someMethod(); } } Any idea why this is not working? somevar.someMethod(); line is generating NPE. 回答1: Is there any reason why the outer class manages the inner instance creation? For example does the inner object need a reference to the outer one?

SignalR Hubs Clients are null when firing event

孤者浪人 提交于 2021-01-21 12:30:35
问题 I've written a generic hubs which I'm having some issues with so to debug it I've decided to make a simple connection count like so: public class CRUDServiceHubBase<TDTO> : Hub, ICRUDServiceHubBase<TDTO> { public const string CreateEventName = "EntityCreated"; public const string UpdateEventName = "EntityUpdated"; public const string DeleteEventName = "EntityDeleted"; protected int _connectionCount = 0; public Task Create(TDTO entityDTO) { return Clients.All.InvokeAsync(CreateEventName,

Spring boot auto configuration with dependency and without @ComponentScan

女生的网名这么多〃 提交于 2021-01-20 20:12:32
问题 Spring boot provides @ComponentScan to find packages to be scanned. I am building a library which has @RestControllers inside with package com.mylib.controller . There are other classes as well with stereotype annotations in different packages. So, if some one is developing SpringBoot Application with com.myapp base package. He uses my library in his application. He need to mention @ComponentScan("com.mylib") to discover stereotype components of library. Is there any way to scan components

Spring boot auto configuration with dependency and without @ComponentScan

十年热恋 提交于 2021-01-20 20:10:34
问题 Spring boot provides @ComponentScan to find packages to be scanned. I am building a library which has @RestControllers inside with package com.mylib.controller . There are other classes as well with stereotype annotations in different packages. So, if some one is developing SpringBoot Application with com.myapp base package. He uses my library in his application. He need to mention @ComponentScan("com.mylib") to discover stereotype components of library. Is there any way to scan components

Provider vs. Get_it

送分小仙女□ 提交于 2021-01-20 19:00:31
问题 Searching for Dependency Injection solutions for Flutter, I found two awesome libraries: provider and get_it . As far as I can see, provider has more boilerplate, but it fits really nicely with Flutter, allowing Consumer to rebuild parts of the Widget tree onde an injected value change. get_it on the other hand is more straightforward, easier to use, and not dependant on Flutter, so can be used with any Dart code. Are there any more differences and limitations between them? I know this is

Inject generic interface in .NET Core

左心房为你撑大大i 提交于 2021-01-20 16:12:06
问题 I want to inject this interface to my controllers: public interface IDatabaseService<T> where T : class { T GetItem(int id); IEnumerable<T> GetList(); void Edit(T data); void Add(T data); void Remove(T data); } I want to use generic, because in my WebApi project i have controllers like ProjectController , TaskController etc and i want to use generic interface to each of type (for example, IDatabaseService<Project> , IdatabaseService<Task> etc). Class, that will be injected to controller will

Inject generic interface in .NET Core

心已入冬 提交于 2021-01-20 16:11:38
问题 I want to inject this interface to my controllers: public interface IDatabaseService<T> where T : class { T GetItem(int id); IEnumerable<T> GetList(); void Edit(T data); void Add(T data); void Remove(T data); } I want to use generic, because in my WebApi project i have controllers like ProjectController , TaskController etc and i want to use generic interface to each of type (for example, IDatabaseService<Project> , IdatabaseService<Task> etc). Class, that will be injected to controller will

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

流过昼夜 提交于 2021-01-20 15:58:33
问题 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