dependency-injection

Circular dependency tree, justified or not

冷暖自知 提交于 2019-12-12 11:49:11
问题 I've came up with some solution on which my IoC/DI container ( Castle Windsor ) is claiming that there's a cyclic dependency tree. And it's true. But I'm not that sure that this cycle is that harmful. This is, more or less, the dependency tree: A WebAPI controller depends on... ...a service A depends on... ...an unit of work depends on... ...a repository depends on... ...a domain event manager (1) depends on many... ...domain event handlers, and one depends on... ... service A (2) (1) A

How to tell Ninject to inject the same instance for nested constructors?

て烟熏妆下的殇ゞ 提交于 2019-12-12 11:31:53
问题 I have a Windows Service application, where I would like to use Ninject for my service classes. There are some service classes which use other, let's say "lower level", or more generic service classes. Each service usually needs a repository for data access. So for example I have an IRepository interface, an IServices1 and an IServices2 interface. There are Services1 and Services2 implementations of the latter two, both having a constructor parameter of type IRepository. Now assume that

Dependency injection with parallel processing

倖福魔咒の 提交于 2019-12-12 11:12:03
问题 I am trying to practice manual dependency injection (no framework yet) to remove tight coupling in my code. This is just for practice - I don't have a specific implementation in mind. So far simple constructor injection has worked fine. However I cannot work out how to solve creating a tight coupling when one class must use another within a parallel loop. Example: public class Processor { private IWorker worker; public Processor(IWorker worker) { this.worker = worker; } public List<string>

Dependency Injections are undefined in controller functions while using Angular1+ ES6, with controller as a class

£可爱£侵袭症+ 提交于 2019-12-12 11:00:00
问题 I am using ES6 class to define my controller so this is the syntax, export class SearchBarController { constructor($log) { 'ngInject'; $log.debug("Hello"); } textTyped($log){ $log.debug("change fired."); } } view : <input type="text" data-ng-model="vm.txt" data-ng-change="vm.textTyped()"/> So "Hello" from within the constructor is getting logged fine. But, "change fired" within the typedText() function is not firing because apparently is undefined how do I make my class function textTyped()

Dependency Injection: How to configure interface bindings for wrapping

三世轮回 提交于 2019-12-12 10:58:43
问题 So, let's say I have an interface IThingFactory : public interface IThingFactory { Thing GetThing(int thingId); } Now, let's say I have a concrete implementation that retrieves Thing s from a database. Now, let's also say I have a concrete implementation that wraps an existing IThingFactory and checks for a Thing 's presence in, say, an in-memory cache before hitting the wrapped IThingFactory . Something like: public class CachedThingFactory : IThingFactory { private IThingFactory _wrapped;

AngularJS: inject service into directive?

风流意气都作罢 提交于 2019-12-12 10:56:37
问题 I've been trying to integrate D3.js with Angular, and am following this tutorial: http://www.ng-newsletter.com/posts/d3-on-angular.html The tutorial creates a d3 module which contains d3Service , and that gets injected into a directive. My app has a slightly different structure, but whenever I try to inject the d3 service, it shows up as undefined in my directive link function. I can inject the d3 service into my controller without issue. Here's what I'm doing: app.js : var sentimentApp =

Is there a way to have ASP.NET 5 Dependency Injection resolve a DbContext without a reference?

左心房为你撑大大i 提交于 2019-12-12 10:55:38
问题 I am doing some prototyping with MVC 6 and have run into a quandary. Our project architecture is straightforward enough: Data Tier (Entity Framework 6) Service Tier (Class Library, references Data Tier) Presentation Tier (MVC 4, references Service Tier, does not reference Data Tier) I'm attempting to keep the design as similar to the original as possible, even after reading (and agreeing with) the Composition Root pattern. This means that my new MVC 6 application is unaware of my DbContext

How do I manage object disposal when I use IoC?

﹥>﹥吖頭↗ 提交于 2019-12-12 10:53:28
问题 My case it is Ninject 2. // normal explicit dispose using (var dc = new EFContext) { } But sometimes I need to keep the context longer or between function calls. So I want to control this behavior through IoC scope. // if i use this way. how do i make sure object is disposed. var dc = ninject.Get<IContext>() // i cannot use this since the scope can change to singleton. right ?? using (var dc = ninject.Get<IContext>()) { } Sample scopes Container.Bind<IContext>().To<EFContext>()

DI with auto-generated web service clients

非 Y 不嫁゛ 提交于 2019-12-12 10:45:32
问题 I'm trying to do dependency injection throughout the app tier and am running into a scenario I'm sure others have seen. There are some 3rd party web services that we consume and the clients were auto-generated with a base class. The clients do not have an interface and the data types are in the same file/project. The obvious problem is if I want to do unit testing I'll need to mock the service. I'll need to extract an interface and move the data types into a "contracts" project that is

spring: a bean that receives a list of Classes

拥有回忆 提交于 2019-12-12 10:44:29
问题 I want to define in my Spring XML context a bean that has a property of the type List of classes: i.e. List<Class<?>> classes How do I send that bean a number of classes, say java.lang.String and java.lang.Integer? The list needs not be reusable, i.e. I will not refer to it in another bean. 回答1: With Spring, the simplest possibility usually works..... <property name="classes"> <list> <value>java.lang.String</value> <value>java.lang.Integer</value> </list> </property> 回答2: <property name=