dependency-injection

Delaying a task in C# - db context disposed

安稳与你 提交于 2021-02-15 04:59:28
问题 I have a situation where I need certain code to execute at a certain time (in my ASP .NET Core project). I know that delaying a task is not a great solution, but this is what I have and I'd like to know how to make it work: async Task MyMethod() { // do something // Create a new thread that waits for the appropriate time TimeSpan time = dbAppointment.ScheduledOn - TimeSpan.FromMinutes(5.0) - DateTime.UtcNow; _ = Task.Delay(time).ContinueWith(async x => await notificationManager.CreateReminder

IHttpContextAccessor.HttpContext.User.Identity shows all null properties in CurrentUserService service

谁都会走 提交于 2021-02-15 04:57:10
问题 I am trying to use Jason Taylor's Clean Architecture Template, this template uses NSwag to automatically create a TypeScript Client (Angular), but I don't need to create a TS client, so my main goal is to replace it with Razor Pages. I've been able to achieve this to a high grade, but I'm having trouble with the CurrentUserService whenever it gets instantiated it is supposed to set the UserId in this line: UserId = httpContextAccessor.HttpContext?.User?.FindFirstValue(ClaimTypes

IHttpContextAccessor.HttpContext.User.Identity shows all null properties in CurrentUserService service

我的梦境 提交于 2021-02-15 04:54:09
问题 I am trying to use Jason Taylor's Clean Architecture Template, this template uses NSwag to automatically create a TypeScript Client (Angular), but I don't need to create a TS client, so my main goal is to replace it with Razor Pages. I've been able to achieve this to a high grade, but I'm having trouble with the CurrentUserService whenever it gets instantiated it is supposed to set the UserId in this line: UserId = httpContextAccessor.HttpContext?.User?.FindFirstValue(ClaimTypes

League route, container, and PDO

╄→гoц情女王★ 提交于 2021-02-11 14:41:55
问题 TL;DR; How do I make a PDO connection available to the CardOnFile\Controller class so that it can make database queries? (I think I have to use the container, but not sure how). Background I want to avoid having multiple connections to the database each time I instantiate an object that needs database access. So, I think I need to instantiate ONE copy of a database connection (PDO) and then inject it into the classes where it will be needed using League\Route and League\Container. I don't

How to resolve generic interface to generic implementation when using dependency injection?

元气小坏坏 提交于 2021-02-11 13:01:53
问题 I have created a generic repository that I want to be used in a service. public abstract class AbstractBaseRepository<TEntity, TEntityKey> : IBaseRepository<TEntity, TEntityKey> where TEntity : class, IBaseEntity<TEntityKey>, new() { /* some code */ } And the interface: public interface IBaseRepository<TEntity, TEntityKey> { /* some code */ } On my service I inject the repository like this: public class TenantsService : AbstractBaseService<TenantEntity, int> { public TenantsService

How to resolve generic interface to generic implementation when using dependency injection?

☆樱花仙子☆ 提交于 2021-02-11 13:01:36
问题 I have created a generic repository that I want to be used in a service. public abstract class AbstractBaseRepository<TEntity, TEntityKey> : IBaseRepository<TEntity, TEntityKey> where TEntity : class, IBaseEntity<TEntityKey>, new() { /* some code */ } And the interface: public interface IBaseRepository<TEntity, TEntityKey> { /* some code */ } On my service I inject the repository like this: public class TenantsService : AbstractBaseService<TenantEntity, int> { public TenantsService

How to share instance between decoratee and decorator in the context of ScopedLifestyle.Flowing

主宰稳场 提交于 2021-02-11 12:53:43
问题 I don't understand how to to share instance between decoratee and decorator by using a DI container. The following example illustrates my problem. The context instance is shared between the TransactionCommandDecorator and the Command service. var context = UowFactory.GetUnitOfWork(); var command = new TransactionCommandDecorator( context, new Command(context)); command.Execute(new CommandParams { }); context.dispose(); Basically I need to have a lot of commands that interact with the database

Nested dependency injection through Property wrapper crashes

三世轮回 提交于 2021-02-11 12:12:05
问题 Followed this it was working fine. But when I tried the same thing for resolving a nested dependency (Dependency injected class has a dependency in turn - NetworkService In our case), it crashed. What am I doing wrong here? any help would be highly appreciated. A realtime scenario class AppContainer { static let shared = AppContainer() var index: [Any] = [NetworkingLibrary(), NetworkService()] func resolve<T>(_ type: T.Type) -> T { return index.first(where: { $0 as? T != nil }) as! T } }

Nested dependency injection through Property wrapper crashes

﹥>﹥吖頭↗ 提交于 2021-02-11 12:11:07
问题 Followed this it was working fine. But when I tried the same thing for resolving a nested dependency (Dependency injected class has a dependency in turn - NetworkService In our case), it crashed. What am I doing wrong here? any help would be highly appreciated. A realtime scenario class AppContainer { static let shared = AppContainer() var index: [Any] = [NetworkingLibrary(), NetworkService()] func resolve<T>(_ type: T.Type) -> T { return index.first(where: { $0 as? T != nil }) as! T } }

Spring IllegalAccessException after isolating a module in a separate ClassLoader

早过忘川 提交于 2021-02-10 17:15:02
问题 I have had a problem involving jar clash between incompatible versions of BouncyCastle. We have solved it by creating a bean that, using a Spring-defined ClassLoader bean injected as property, invokes services from classes not stored in official WEB-INF/lib folder. Following are the beans definitions <bean id="metainfJarClassloader" class="com.jdotsoft.jarloader.JarClassLoaderFactory" factory-method="create"/> <bean id="jadesFactory" class="it.csttech.proxy.jades.JadesFactory"> <constructor