dependency-injection

Injected Dependency is undefined in Unit Test

你。 提交于 2019-12-24 15:15:47
问题 I'm new to Angular and I'm not quite sure exactly how dependency injection works. My problem is that I have Service A which depends on Service B, but when I inject Service A into my test Service B becomes undefined. I have seen Injecting dependent services when unit testing AngularJS services but that problem is a bit different than mine. This Injected Dependencies become undefined in angular service is very similar to my issue but I couldn't translate the JS. I have also changed my variable

Using IoC to resolve model objects in Action Methods

别等时光非礼了梦想. 提交于 2019-12-24 15:06:51
问题 I'm using IoC container for dependency injection in Asp.Net MVC 3 and everything seems perfect until I started to write Action methods in my controller. What is the best way to create entity/model objects within the action methods? Sometimes models are retrieved from certain repository or service which are injected to the controller via the constructor, but its not the case with many other model objects in the system. 回答1: An IOC container is best used for creating components; but it shouldn

Dependency Injection with Ninject and Global Filter: IAuthorizationFilter

杀马特。学长 韩版系。学妹 提交于 2019-12-24 14:58:19
问题 I use standart NinjectMVC3 Bootstrapper installed in the App_Start folder. My application class looks like: public class MvcApplication : HttpApplication { static void RegisterRoutes(RouteCollection routes) { // ... routes here ... } public void Application_Start() { AreaRegistration.RegisterAllAreas(); RegisterGlobalFilters(GlobalFilters.Filters); RegisterRoutes(RouteTable.Routes); } static void RegisterGlobalFilters(GlobalFilterCollection filters) { // empty } } I have only following

Inject HttpServletRequest (from Struts2 action implementing ServletRequestAware) into property using Spring

ぃ、小莉子 提交于 2019-12-24 14:49:45
问题 I am using Struts2 with Spring for dependency injections. I have Struts action A from which I can access HttpServletRequest and some dependency B inside it: public class A extends ActionSupport implements ServletRequestAware { private B b; private HttpServletRequest request; @Override public void setServletRequest(HttpServletRequest httpServletRequest) { this.httpServletRequest = httpServletRequest; } public B getB() { return this.b; } public void setB(B b) { this.b = b; } } There is also

Using Ninject to inject dependencies into externally constructed objects (user control)

◇◆丶佛笑我妖孽 提交于 2019-12-24 13:32:24
问题 I would like to use Ninject in my WinForms application. I cannot figure out how to use it for my user controls. Sometimes they rely on the services I want to configure through the DI framework. These controls need to be manageable through the designer (thus need default constructors). So, is there a way to inject dependencies into properties of this user control? Since the designer needs to be able to construct it, kernel.Get<TestClass> won't work here. Is there a method or some code that

How to bind a string to a method of an object when it is injected into another?

会有一股神秘感。 提交于 2019-12-24 13:29:43
问题 I have a NHibernate.Cfg.Configuration provider. ConfigurationProvider public class ConfigurationProvider : Provider<Configuration> { public class ConfigurationProvider(string connectionString , Assembly mappings) { ConnectionString = connectionString; Mappings = mappings; } protected override Configuration CreateInstance(IContext context) { var c = new Configuration().Configure(); c.AddAssembly(Mappings); c.Properties["connection.connection_string"] = ConnectionString; return c; } private

Windsor Castle resolving multiple dependencies with same interface

江枫思渺然 提交于 2019-12-24 13:08:31
问题 Problem: Class constructor is as below: public class ParsingRulesProvider : IParsingRulesProvider{ public ParsingRulesProvider(List<IParsingRule> rules){} } We have two rules: public class ARule : IParsingRule{ public ARule(IASomeObject someObject){} } public class BRule : IParsingRule{ public BRule(IBSomeObject someObject){} } Questions: How to register in code: ParsingRulesProvider with rule A and B? ParsingRulesProvider with all objects implementing IParsingRule? ARule and BRule ? 回答1: AD1

N-Dependency injection in C - better way than linker-defined arrays?

你。 提交于 2019-12-24 13:04:03
问题 Given a library module , in the following called Runner , which resides as a reusable component (no recompilation required, i.e. static link library) in the app partition of the architecture, not the main partition . Note that it only contains main() for demo purposes. Given a set (order irrelevant) of other modules / objects called Callable s, i.e. Callable1 , Callable2 and Callable3 , which also reside as reusable components in the app partition . Runner has a runtime dependency on the

Injecting @Stateful bean into another @Stateful bean

非 Y 不嫁゛ 提交于 2019-12-24 12:17:44
问题 On a glassfish 3.1 server, I have a @Stateful session bean which is injected into another stateful session bean. The stateful session bean which is injected presents my entity access layer, it itself has it's EntityManager injected with @PersistenceContext and it looks like this. @Stateful MyEAO { @PersistenceContext EntityManager em; MyEAO() { // default constructor } .... } This access layer is injected into another stateful bean: @Stateful public class ShopAdmin implements

Can't get Spring to inject my dependencies

可紊 提交于 2019-12-24 12:10:09
问题 I've been trying to get Spring to inject an @Autowired dependency into my application without avail. What am I doing wrong? I created a bean called TimeService. Its job is to return the current time to anyone that asks. package com.foxbomb.springtest.domain.time; import java.util.Date; import org.springframework.stereotype.Service; @Service public class TimeService { public TimeService() { super(); System.out.println("Instantiating TimeService..."); } public Date getTime() { return new Date()