dependency-injection

Is there any hard data on the value of Inversion of control or dependancy injection?

I've read a lot about IoC and DI, but I'm not really convinced that you gain a lot by using them in most situations. If you are writing code that needs plugable components, then yes, I see the value. But if you are not, then I question whether changing a dependancy to a class to a dependancy of an interface is really gaining you anythi...

Problems with MVC Controllers + Dependency Injection (Ninject) in medium trust

I want to use dependency injection in an medium trust environment. To that aim I picked Ninject as Iv been told its light weight. How do I set-up injection into the controllers? When I tried to create a custom controller factory: public class NinjectControllerFactory : DefaultControllerFactory { private readonly IKernel...

IoC/DI framworks with Smart Client Winform apps: How should I approach this?

I'm starting a new Winforms app, and I intend to use an IoC/DI framework (probably Ninject, but i'm also thinking about StructureMap and LinFu). It seems like nearly everyone who is using IoC/DI is doing so in a web based environment and have found virtually nothing on using Winforms with it. I'd like to know if anyone is using IoC/DI ...

How can I resolve the conflict between loose coupling/dependency injection and a rich domain model?

Edit: This is not a conflict on the theoretical level but a conflict on an implementation level. Another Edit: The problem is not having domain models as data-only/DTOs versus richer, more complex object map where Order has OrderItems and some calculateTotal logic. The specific problem is when, for example, that Order needs to grab the...

Using dependency injection in a library

I'm writing a java library that will be used by an existing application. I'm using dependency injection so testing is easier, and I'm familiar with Spring so I was planning to use it to manage the dependency injection while testing. The applications that will eventually use the library are not Spring-based, however, nor does it use any...

Custom Controller Factory, Dependency Injection / Structuremap problems with ASP.NET MVC

I recently tried to implement dependency injection using StructureMap. I managed to follow the example all the way but I'm encountering a thrown exception every time I try to run the application. Here's some code snippets from my controller factory. public class StructureMapControllerFactory : DefaultControllerFactory { protected ov...

circular dependency control in OCAML

Hi everyone, [EDIT] Thank you for your answer, my problem is the following : Module A called Map.ml let lst = ref [Instance1_ModuleB; Instance2_ModuleB; ...];; let is_coliding p = DoSomeWork_And_Return_A_Bool ;; .... other things here. Module B called Player.ml Open Map class player_object (x_in, y_in, name_in)= object (self) me...

Refactoring a method having dependencies within the same object into something more testable (PHP)

I currently have a method within my class that has to call other methods, some in the same object and others from other objects. class MyClass { public function myMethod() { $var1 = $this->otherMethod1(); $var2 = $this->otherMethod2(); $var3 = $this->otherMethod3(); $otherObject = new OtherClas...

Dependency Injection Lifecycles

I have a singleton service with a dependency on a service with a request scoped lifecycle. If I allow the container to inject the request scoped service when I first get the singleton it will be fine for the current request but will be disposed of in any subsequent request. Does this mean I have to use the dependency container to cre...

When would you use the Common Service Locator ?

I've been looking at the Common Service Locator as a way of abstracting my IoC container but I've been noticing that some people are strongly against this type of this. Do people recommend never using it? Always using it? or sometimes using it? If sometimes, then in what situations would you use it and what situations would you not use ...

Help with Dependency Injection in .NET

Can someone explain dependency injection with a basic .NET example and provide a few links to .NET resources to extend on the subject? This is not a duplicate of http://stackoverflow.com/questions/130794/what-is-dependency-injection because I am asking about specific .NET examples and resources. ...

Linq to SQL, Entity Framework, Repository Pattern, and Dependency Injection

Hello: Stephan Walters video on MVC and Models is a very good and light discussion of the various topics listed in this questions title. The one question listed in the notes unanswered was: If you create an Interface / Repository pattern for Linq2SQL, does Linq2SQLs classes still cause a dependency on Linq, even though you pass the cl...

Structuremap 2.0 documentation

I'm just starting to learn DI/IOC methods and like what I see so far from Structuremap. The problem is that my current project is limited to .NET 2.0 so I cannot use the new version (2.5) of Structuremap. That being said, can someone point me towards some documentation for v2.0? Most articles and tutorials use v2.5 and only a small fe...

[STRUTS 2.1.6] SessionAware does not inject session Object

Hello guys, Once more here I come with a question of s2, i'm a beginner at it and got some trouble finding examples. I'm build a menu service wich depends upon a login, wich is give when the user enter at start page. Once the login has been made, I store the user object into the session by doing the follow: @Override public String int...

Controller ModelState with ModelStateWrappper

HI, to all, i am use Structure Map to implement dependency-injection. I created ModelStateWrapper class to send Model state in service layer, which in constructor get reference to ModelState of controller. In bootswrapper i registered my type: ForRequestedType<ISourceService>() .TheDefaultIsConcreteType<SourceService>(); For...

Enforcing dependencies in IoC via a constructor?

I'm trying to come to terms with using IoC/Dependency Injection while at the same time programming to contracts rather than specific classes. The dilemma I'm having is the tension between: Do program to interfaces for IoC: I started out with IoC relying heavily on interfaces. Judging by Spring's sample projects, interfaces are the way ...

Java: Dependency Injection on foreign-constructed objects?

Hello! I'm a huge fan of D.I. I'm currently developing a not-so-small project which uses D.I. everywhere (classic and beautiful D.I. by hand). From my point of view there are following advantages: It's intuitive when you got used to it, doesn't affect readability in negative way (in fact, it gets even better), but the most importan...

Why there's no configuration file at all for dependency injection with Google Guice?

I am checking out Google Guice as DI framework but I am a bit puzzled: why there's no configuration file at all? I found a partial explanation on this question but it is still not clear how I would be able to set my component roles (or any other thing I need to use a switch) without a config file. Any help appreciated! ...

Who is responsible for attaching listeners in a no-initialization dependency injection scheme?

I've been reading through Misko Hevery's Guide: Writing Testable Code. I definitely buy into dependency injection as a great tool to improve testability, and use it a lot in my code. However, when reading the first part of the guide "Flaw #1: Constructor does Real Work", I find I'm still a bit fuzzy on how you're supposed wire up event...

Unity Dependency Injection - how to RegisterInstance in .config?

This is a C# Asp.net MVC project. I've currently got the Unity mappings set up in the global.asax.cs. I'd like to move the container setup from code, to the web.config. All has gone fine with my own types, but now I need to translate this line : container.RegisterInstance(System.Web.Security.Membership.Provider); (All the other co...