dependency-injection

[StructureMap] Xml configuration or Configuration through code?

I personally like the option to configure StructureMap from C# code. From what I understand, one of the advantages of DI, is that we can easily swap in a new concrete instance. But, if the configuration is defined in code, then the concrete instances are hardcoded in the dll. So, practically, its as good as having hard coded the depend...

Accessing legacy out-of-container instantiated objects from Spring beans

We have a legacy system where something like a Service Locator is used to instantiate and provide all service objects: class ServiceLocator { ServiceA serviceA; ServiceB serviceB; public ServiceLocator () { serviceA = ...; serviceB = ...; } public ServiceA getServiceA() { return serviceA; ...

Application Variable in WPF While Maintaining Testability

I am working on a WPF application, using the MVVM Pattern. Each ViewModel will need access to a security object, that essentially provides information about the rights the user has. Because this object only needs to be populated once at start up, and because populating it is (at least potentially) expensive, I want to keep it in state ...

Spring injection failure after update to Grails 1.2.1

I used an older grails version, latest that was out in November 2009, and upgraded to 1.2.1 now. Unfortunately. I did not touch the app, checked it out of VCS. Now the spring injection does not work anymore. I depend on external libraries (JmsTemplate, ActiveMQ, ...) and define all the beans in my resources.xml file. To test if spring i...

IOC best practice: How to best manage dependency graph?

I am doing an MVC project with structuremap as an IOC container. We are doing TDD, and I want to set up my dependencies so that its easy to work with, and so that its easy to test. How should I best set up the graph of dependencies for the below fictional illustrated graph ? ApplicationController Controller AuthenticationService Us...

DI-Container: Howto pass configuration to objects

Sometimes I have classes which need to get some information for construction. I am not talking about references to other objects (which will be injected) but about (for instance) strings which are holding unique information: // Scoped as singleton! class Repository { public Repository( InjectedObject injectedObject, string path ) { ...

Not sure how to use Dependency Injection + Repository Pattern + Unit Of Work Pattern with a WinForm application.

(apologies for the Wall Of Text... :) ) Summary Using Dependency Injection with my Winfor application is creating a large number of Repository Context's. I'm not sure if the way i'm using this is right or wrong, or what the common practice is. Details In the last 6 odd months, I've been making ASP.NET MVC applications that impliment...

What should be the strategy of unit testing when using IoC ?

After all what I have read about Dependency Injection and IoC I have decided to try to use Windsor Container within our application (it's a 50K LOC multi-layer web app, so I hope it's not an overkill there). I have used a simple static class for wrapping the container and I initialize it when starting the app, which works quite fine for ...

Spring: constructor injection of primitive values (properties) with annotation based configuration

I'm trying to configure a class with Annotation based configuration in Spring 3, which takes primitive values as its constructor arguments: @Component class MyBean { MyBean(String arg1, String arg2) { // ... } } And an application context like this: <beans [...]> <context:component-scan base-package="com.example" /> <cont...

How to manage configuration of components loaded via dependancy injection?

Hi, I am building a application which will use DI Framework to load components to fetch data, from various sources like external web service or DB. Now components will need some of application configuration like web service url or database connection string. Keeping all that stuff in Web.Config and passing it via constructor parameters i...

How do I test a controller that has an Authorize attribute and dependencies injection by IoC?

Hi I’ve taken over an ASP.NET MVC project from a colleague. I have only a rudimentary knowledge of both ASP.NET MVC and unit testing. I’m trying to get off on the right foot by creating unit tests. I thought I’d start with testing a controller. Unfortunately I stumbled at the first hurdle! The controller in question has the Authorize ...

What DLL is the Bind(Of T) from Ninject located in.

I am using .Net 3.5 and a console application that eventually will become a windows service. Most of the examples I find use something like Bind<IWeapon>().To<Sword>(); I have included all the DLL as references in my project and I the compiler is still complaining. Any clues of where I am going wrong? Sorry this might be a stupid qu...

In Python, what's a good pattern for disabling certain code during unit tests?

In general I want to disable as little code as possible, and I want it to be explicit: I don't want the code being tested to decide whether it's a test or not, I want the test to tell that code "hey, BTW, I'm running a unit test, can you please not make your call to solr, instead can you please stick what you would send to solr in this s...

Seam not injecting Stateful EJB dependencies

I have not been able to find a solution to this problem and my post to the Seam forum has gone unanswered. I am hope someone here can help. I am a noob working with Seam, so I am sure I am just doing something stupid. Any help anyone can give me would be greatly appreciated... I have wasted hours and gotten nowhere. I used the jboss to...

Thought on Code to Interface in Spring?

I know in spring we all code to interface. So the implementation class should not be known to outside world at all. But it is a public class so anyone make an instance of the implementation class also. How do you prevent this? Do you make the constructor private? Since spring creates an instance of through reflection, it should be fine. ...

Using Ninject, if I create a custom provider must I ensure a single instance or can I use the SingleInstance attribute?

Hi I am hoping either Peter or Ruben sees this question as they seem to be the go to guys regarding Ninject. I needed to create a custom provider because I have a class that takes 4 arguments. The two can be injected because they are types but the other two are configuration parameters and are integers. They refer to timeouts in millise...

Are custom config sections dependencies that should be injected?

Also, how do connection strings fit in? Presumably, it is ok for the dal to read these values from the config, or should these be passed down from the top? ...

Deserialized bean needs scoped dependencies

How can I inject dependencies into a deserialized bean? Some of my Spring beans should be serialized during the render-response phase of our JSF application, and then deserialized at the beginning of the next request. Some of those beans have dependencies which are scoped to the request. If I configure the dependencies with the scoped...

Dependency injection - am I missing something?

Hi, I am using structuremap in an asp.net (mvc) project and I am fairly happy with the functionality. One thing just came to me where I am not sure if I am too blind to see. I get several services instantiated in my controller class by structure map, but I want them to share methods that are base (hint) to all services. How can I achiev...

Using Ninject 2.0 with ASP .Net 3.5

Hi, I am trying to use Ninject 2.0 with Asp .Net 3.5 web application. Following are the DLLS and it's versions I am using. Ninject.dll - v2.0.0.0 Ninject.Extensions.Logging.dll v2.0.0.0 Ninject.Web.dll v1.0.0.0 In my global.ascx.cs I have following method. protected override IKernel CreateKernel() { IKernel kernel = new...