inversion-of-control

IoC, Where do you put the container?

I'm using castle windsor for a pet-project I'm working on. I'm starting to notice that I need to call the IoC container in different places in my code to create new objects. This dependency on the container makes my code harder to maintain. There are two solutions I've used to solve this problem I tried to create abstract factories as ...

Where can I find an .xsd file to provide intellisense for Castle Windsor?

I'm looking for an .xsd schema file to drop into my Visual Studio directory to provide intellisense for the xml configuration file for the Castle Windsor IoC container. I've looked in the downloaded code for Windsor, as well as googled several different ways. I see many people asking the same question, but no answers. Anyone know if ther...

Is there any reason to not use my IoC as a general Settings Repository?

Suppose that the ApplicationSettings class is a general repository of settings that apply to my application such as TimeoutPeriod, DefaultUnitOfMeasure, HistoryWindowSize, etc... And let's say MyClass makes use of one of those settings - DefaultUnitOfMeasure. My reading of proper use of Inversion of Control Containers - and please corr...

Does the size of the constructor matter if you're using Inversion of Control?

So I've got maybe 10 objects each of which has 1-3 dependencies (which I think is ok as far as loose coupling is concerned) but also some settings that can be used to define behavior (timeout, window size, etc). Now before I started using an Inversion of Control container I would have created a factory and maybe even a simple ObjectSett...

Is MEF a replacement for System.Addin?

Is the Managed Extensibility Framework a replacement for System.Addin? Or are they complementary? ...

What is Castle Windsor, and why should I care?

I'm a long-time Windows developer, having cut my teeth on win32 and early COM. I've been working with .Net since 2001, so I'm pretty fluent in C# and the CLR. I'd never heard of Castle Windsor until I started participating in Stack Overflow. I've read the Castle Windsor "Getting Started" guide, but it's not clicking. Teach this old d...

Guidelines for designing classes for dependency injection.

This question about unit testing best practices mentions designing classes for dependency injection. This got me thinking as to what exactly that might mean. Having just started working with inversion of control containers I have some ideas on the issue, so let me throw them against the wall and see what sticks. The way I see it, th...

How to pass arguments to a constructor in an IOC-framework

How can I pass arguments to a constructor in an IOC-framework? I want to do something like: (Trying to be IOC-framework agnostic ;) ) object objectToLogFor = xxx; container.Resolve<ILogging>(objectToLogFor); public class MyLogging : ILogging { public MyLogging(object objectToLogFor){} } It seems that this is not possible in Stru...

What is the proper way to inject a data access dependency for lazy loading?

What is the proper way to inject a data access dependency when I do lazy loading? For example I have the following class structure class CustomerDao : ICustomerDao public Customer GetById(int id) {...} class Transaction { int customer_id; //Transaction always knows this value Customer _customer = null; ICustomerDao _customer_d...

IoC Containers - Which is best? (.Net)

I'd like to get a feel for what people are using for IoC containers. I've read some good things about Castle Windsor, but I know a lot of people use StructureMap, Unity, Ninject, etc. What are some of the differences amongst those mentioned (and any I neglected). Strengths? Weaknesses? Better fit (like StructureMap is great for ABC but...

Difference between Dependency Injection (DI) & Inversion of Control (IOC)

I've been seeing a lot of references Dependency Injection (DI) & Inversion of Control (IOC), but I don't really know if there is a difference between them. I would like to start using one or both of them, but I'm a little confused as to how they are different. ...

How do you pass an object to a windsor container instead of a type?

I have the following class: public class ViewPage<TView,TPresenter> : Page where TView : IView where TPresenter : Presenter<TView> { public ViewPage() { if (!(this is TView)) throw new Exception(String.Format("The view must be of type {0}", typeof(TView))); IWindsorContainer container = new WindsorContainer(); container.A...

Which Dependency Injection Tool Should I Use?

I am thinking about using Microsoft Unity for my Dependency Injection tool in our User Interface. Our Middle Tier already uses Castle Windsor, but I am thinking I should stick with Microsoft. Does anyone have any thoughts about what the best Dependency Injection tool is? Autofac Castle MicroKernel/Windsor ObjectBuilder PicoContainer...

How can circular dependencies be avoided when callbacks are used?

How can you avoid circular dependencies when you're designing two classes with a producer/consumer relationship? Here ListenerImpl needs a reference to Broadcaster in order to register/unregister itself, and Broadcaster needs a reference back to the Listeners in order to send messages. This example is in Java but it can apply to any OO l...

Dependency Injection book recommendation(s)

It seems like there are very few books (yes, I read books) on Dependency Injection. The Amazon tag for "dependency injection" lists only a few titles, and all of them are specifically about Spring for Java. Are there any books out there that cover DI/IoC in general? Or any that include a survey of multiple DI frameworks? Or any that cov...

How should I order my ctor parameters for DI/IOC?

I'm a bit of a DI newbie, so forgive me if this is the wrong approach or a silly question. Let's say I have a form which creates/updates an order, and I know it's going to need to retrieve a list of products and customers to display. I want to pass in the Order object that it's editing, but I also want to inject the ProductsService and ...

How best to modify my model in Spring MVC if I care about IOC

I am building an application using Spring MVC. I want to make certain changes to my Model for every Controller in the application. In particular, I want to insert certain extra data into the model which will be present for all pages of the application. I could do this several ways: just add the data at the end of every Controller, use a...

Windsor Container: How to specify a public property should not be filled by the container?

When Instantiating a class, Windsor by default treats all public properties of the class as optional dependencies and tries to satisfy them. In my case, this creates a rather complicated circular dependency which causes my application to hang. How can I explicitly tell Castle Windsor that it should not be trying to satisfy a public p...

Windsor Container and internal properties

Is there any solution how to initialize properties of component marked as 'internal'? What assembly name should I use for InternalsVisibleTo attrribute or it won't help? ...

Castle Windsor: How to wire up a component to a factory property rather than method

I have the following component public class MyTimer : IMyTimer { public MyTimer(TimeSpan timespan){...} } Where timespan should be provided by the property ISettings.MyTimerFrequency. How do I wire this up in windsor container xml? I thought I could do something like this: <component id="settings" service="MySample.ISettings...