dependency-injection

Dependency injection into custom ViewPage generates weird error

i'm trying to inject stuff into a custom ViewPage (ModelViewPage, from MvcContrib) public class ValidatedModelViewPage<T> : ModelViewPage<T> where T : class { public ValidatedModelViewPage(IEnumerable<IBehavior<IMemberElement>> elementBehaviors) : base(elementBehaviors.ToArray()) { } } and my Autofac registr...

How to Inject Open Connections with an IoC

First, my scenario. I have a service, BillingService, has a constructor like this: BillingService(IInstallmentService, IBillingRepository) The InstallmentService has a constructor that looks like this InstallmentService(IBillingRepository, IInstallmentCalculator) My Billing service is an application service and the methods will coor...

How to programatically use Spring's JdbcTemplate?

We use Spring's JdbcTemplate which is configured through Spring config as illustrated below. Is there a way to do this without injecting the data source? I'd like to just create the JdbcTemplate instance programatically and "initalize" the datasource using TheOracleDS. Our current config: Java class private JdbcTemplate jdbcTemplat...

Grails Integration with another Spring app - dataSource being overloaded.

Hi, I'm currently in the process of building a CRUD tool for an existing Spring-based application. The application is being included in the Grails app as a JAR library which seems to work fine. To make use of the library's own spring context, I used to load it through: def ctx = new ClassPathXmlApplicationContext( 'classpath:/applicat...

Is Dependency Injection Chaining an Anti-Pattern?

Here is the problem, lets say we are making a video game and want to use Dependency Injection. Here is what we have: Game Class // This is just the code to keep track of the overall game logic Character Class // This would be the guys in the game, good and bad guys both Weapon Class // The weapons for the characters So normally when ...

How can I combine MVVM and Dependency Injection in a WPF app?

Can you please give an example of how you would use (your favorite) DI framework to wire MVVM View Models for a WPF app? Will you create a strongly-connected hierarchy of View Models (like where every nested control's ViewModel is a property on a parent's ViewModel and you bind it to nested control's DataContext in XAML) or you would us...

How to use spring to resolve dependencies of an object created manually?

Hi guys! I would like to know if it's possible to use Spring to resolve the dependencies of an object created manually in my program. Take a look at the following class: public class TestClass { private MyDependency md; public TestClass() { } ... public void methodThaUsesMyDependency() { ... md.someMethod...

Integration test for instantiation of a type via DI container

I am running TDD on an ASP.NET MVC web app. Is it standard practice to create integration tests to demonstrate the correct instantiation of a type via the DI container (in my case Castle Windsor)? If so, would you mock out the container, or simply use it as is? Or... is this simply not done for some reason? Thanks. ...

Comparison between Unity and Moq Dependency Injection Frameworks

Faced with choosing a Dependency Injection Framework in a historically MS shop working with C#, I'm interested in finding out the differences between Moq and Unity. Some of the main concerns would include: Ease of use for developers with no background in DI Feature comparison between the two (once everyone becomes familiar with the te...

Accessing Spring bean *not* by dependency injection

We have some domain objects that are created at runtime - not by Spring. These domain objects need access to some service type beans that are being managed by Spring. How can the domain objects that are created at runtime access Spring beans dynamically (not by DI)? ...

Creation of generic type using Spring Config

How can I instantiate a bean with generic type using spring config public class GenericService<T> { ... } Note that T is not the concrete type of a bean property. It is really just the type for one of the methods of the service. In other words.. Can I instantiate new GenericService of type String() or new GenericService of type ...

Dependency Injection framework suitable for as3 games and regular rich media sites

Hi all, Doing a bit of research on dependency injection frameworks for AS3 to retain loose-coupling of classes and boost our re-usability of code. I've been looking heavily at RobotLegs. There's a whole lot I still don't understand about the framework but it seems ideal for our regular Rich Media apps but has anyone used this framework f...

Inversion of Control or Dependency Injection -- anyone doing it in C?

See, for example, here http://stackoverflow.com/questions/139299/difference-between-dependency-injection-di-inversion-of-control-ioc to remind yourself what IoC and DI are. The question and answer here http://stackoverflow.com/questions/820594/is-inversion-of-control-specific-to-oo-languages suggests that it does not require an OO l...

Mono compatible Dependency Injection Framework

Which Dependency Injection frameworks are compatible (and tested) against the Mono 2.4.2.3 runtime (Release Notes)? ...

What are the best practices for class libraries using dependency injection for internal operations?

What should I be careful about when building a class library complex enough to use internal dependency injection? Assuming that it will use Castle Windsor (as an example), what would be the best place/method to configure the container, given that the library will be used by simple console application (with no DI), web forms using the sa...

How to inject with Guice when there are two different constructors?

Total Guice noob here, have read a few articles and seen the intro video, that's about it. Here's my simplified old code that I'm trying to "guicifiy". Can't quite figure out how to, since (as far as I understand), I can only @inject-annotate one of the two constructors? How can a calling class create the one or the other instance? Or w...

Structuremap (or any IoC, really) architecture question

I'm going to use structuremap for a project I'm working on. The basic gist is that I have a repository pattern with an NHibernate implementation, but I want to use StructureMap to load the repositories in case I ever decide to switch to a Linq2Sql or other type of implementation. I know how to initialize structuremap, but my question is ...

Parameter unexpectedly initialized when invoked from unit test

I have a unit test invoking a constructor, passing in a "null" on purpose to test the handling of the null. I expect the method invoked to throw an ArgumentNullException, but when I step through the code, I see the parameter has actually been initialised. This has me stumped, although my gut says it has something to do with the DI cont...

Using dependency injection with Nlog

I'm using Nlog as my logger, however I cant seem to find an Ilogger interface in Nlog namespaces unlike log4net's Ilogger interface, do I have to create my own wrapper? ...

Dependency Injection by type using generics - how does it work?

Using Spring, I can get all beans of a certain type that are currently defined using this: @Resource private List<Foo> allFoos; How does Spring do this? I thought type information of generics was erased at runtime. So how does Spring know about the type Foo of the list and only inject dependencies of the correct type? To illustrate: ...