dependency-injection

Typescript: how to return the proper class and generic type in a dependency

谁都会走 提交于 2020-01-05 02:47:05
问题 I'm trying to find a way to inject an object into another object (dependency injection), in which the container object can return the proper injected object type , and no need to explicitly pass types to the function (type inference). To make sure the injected objects have a common interface and a default behavior, they'd be instances of an Abstract class. Given that I'd need such a behavior at some ponctual place, I would like to avoid using a dependency injection framework to do so. It

Typescript: how to return the proper class and generic type in a dependency

隐身守侯 提交于 2020-01-05 02:46:06
问题 I'm trying to find a way to inject an object into another object (dependency injection), in which the container object can return the proper injected object type , and no need to explicitly pass types to the function (type inference). To make sure the injected objects have a common interface and a default behavior, they'd be instances of an Abstract class. Given that I'd need such a behavior at some ponctual place, I would like to avoid using a dependency injection framework to do so. It

How to configure nested dependency in ASP.NET 5 DI?

て烟熏妆下的殇ゞ 提交于 2020-01-05 02:31:46
问题 I would like to wrap a repository inside another repository that will handle caching while internally using the passed in repository. This way my caching logic can be completely separate from the repository implementation. This pattern would also allow me to easily change from memory cache to distributed cache, that is I could have different caching repositories that use different cache types so I can plug them in depending on the environment. On Azure I could use distributed cache but on a

Using the provider from two different scopes

允我心安 提交于 2020-01-04 18:17:33
问题 I have the following problem with Guice: a singleton service, is injected with provider of context-sensitive information. Until now, context was related only to servlet requests, so I used a @RequestScoped provider, and I was injecting this provider in service like so: @RequestScoped public class ContextProvider<IContext> implements Provider<IContext> { @Override public IContext get() { ... } // returns context } @Singleton public class ServiceImpl implements IService { @Inject private

Using the provider from two different scopes

一曲冷凌霜 提交于 2020-01-04 18:17:26
问题 I have the following problem with Guice: a singleton service, is injected with provider of context-sensitive information. Until now, context was related only to servlet requests, so I used a @RequestScoped provider, and I was injecting this provider in service like so: @RequestScoped public class ContextProvider<IContext> implements Provider<IContext> { @Override public IContext get() { ... } // returns context } @Singleton public class ServiceImpl implements IService { @Inject private

Symfony dependency injection in twig extension

纵然是瞬间 提交于 2020-01-04 14:27:17
问题 Ok, I was trying to create twig extension with dependencies on other service (security.context) and got some troubles. So, here is my service declaration: acme.twig.user_extension: class: Acme\BaseBundle\Twig\UserExtension arguments: ["@security.context"] tags: - { name: twig.extension } and here's my class // acme/basebundle/twig/userextension.php namespace Acme\BaseBundle\Twig; use Symfony\Component\Security\Core\SecurityContext; use Acme\UserBundle\Entity\User; class UserExtension extends

Unclear on how to implement dependency injection

久未见 提交于 2020-01-04 13:07:13
问题 Let's say I have a LoginView and its data context, LoginViewModel, needs to be injected with a service that can authenticate a user based on their username/password. Now let's say that the state of the application is that someone has already logged in, but now they are logging out and I need to redisplay the login screen for the next user. So at this point I need an instance of my LoginViewModel but I'm not sure how to go about getting it. Should I be injecting a LoginViewModel into my

Unclear on how to implement dependency injection

隐身守侯 提交于 2020-01-04 13:07:08
问题 Let's say I have a LoginView and its data context, LoginViewModel, needs to be injected with a service that can authenticate a user based on their username/password. Now let's say that the state of the application is that someone has already logged in, but now they are logging out and I need to redisplay the login screen for the next user. So at this point I need an instance of my LoginViewModel but I'm not sure how to go about getting it. Should I be injecting a LoginViewModel into my

Spring value injection unable to get value from properties

有些话、适合烂在心里 提交于 2020-01-04 08:05:10
问题 I've got a class like this: @Component public class FaultsConfiguration { private int interval; @Autowired public FaultsConfiguration(@Value("${faults.interval}") int interval) { this.interval = interval; } } In application.properties I have this: faults.interval=130 I think the bean should get the value 130 injected into it. Instead when the bean is initialized I get this error: java.lang.IllegalArgumentException: Could not resolve placeholder 'faults.interval' in value "${faults.interval}"

How to Solve Circular Dependency

给你一囗甜甜゛ 提交于 2020-01-04 06:55:07
问题 Hi I have a problem with the structure of my code, it somehow goes into Circular Dependency. Here is an explanation of how my code looks like: I have a ProjectA contains BaseProcessor and BaseProcessor has a reference to a class called Structure in ProjectB . Inside BaseProcessor , there is an instance of Structure as a variable. In projectB there are someother classes such as Pricing , Transaction etc. Every class in ProjectB has a base class called BaseStructure i.e. Structure , Pricing and