inversion-of-control

Dependency Injection for Presenter

I have a Presenter that takes a Service and a View Contract as parameters in its constructor: public FooPresenter : IFooPresenter { private IFooView view; private readonly IFooService service; public FooPresenter(IFooView view, IFooService service) { this.view = view; this.service = service; } } I reso...

StructureMap singleton behavior not working

My code is public static class ContainerBootstrapper { public static void BootstrapStructureMap() { ObjectFactory.Initialize(x => x .ForRequestedType<ValueHolder>() .CacheBy(InstanceScope.Singleton) .TheDefaultIsConcreteType<ValueHolder>()); } } In...

How to register decorated objects in Dependency Injection frameworks (PicoContainer) ?

Hi, I want to wrap a number of classes implementing the Job interface with a JobEnabledDecorator object that determines whether or not it executes. I am having trouble figuring out how to configure this in PicoContainer, so that it knows to create the Job implementation objects with a JobEnabledDecorator wrapping them. Is this possi...

Is this basically what an IOC like NInject does?

Normally I would do this: public class DBFactory { public UserDAO GetUserDao() { return new UserDao(); } } Where UserDao being the concrete implementation of IUserDao. So now my code will be littered with: DBFactory factory = new DBFactory(); IUserDao userDao = factory.GetUserDao(); Use...

How does the Built-in Bindings of Google Guice work?

Hello, I tried Google Guice the first time and find it very nice. But, when I reached the part of Built-in Bindings I do not understand the examples. For me it looks like I can use it for logging like an interceptor, but I don't know how. Could someone of you explain this type of Binding and how I can use it? And maybe (if it's possib...

Using structuremap with log4net wrapper

I have the following interface: public interface ILogger { void Debug(string message, params object[] values); void Info(string message, params object[] values); void Warn(string message, params object[] values); void Error(string message, params object[] values); void Fatal(string message, params object[] values); }...

Is there a pattern for initializing objects created via a DI container

I am trying to get Unity to manage the creation of my objects and I want to have some initialization parameters that are not known until run-time: At the moment the only way I could think of the way to do it is to have an Init method on the interface. interface IMyIntf { void Initialize(string runTimeParam); string RunTimeParam { g...

Can Castle.Windsor do automatic resolution of concrete types

We are evaluating IoC containers for C# projects, and both Unity and Castle.Windsor are standing out. One thing that I like about Unity (NInject and StructureMap also do this) is that types where it is obvious how to construct them do not have to be registered with the IoC Container. Is there way to do this in Castle.Windsor? Am I bein...

Creation Of Object That Uses Inversion Of Control

I'm creating a CSV reader (yes I know about Fast CSV Reader and FileHelpers). The CsvReader class uses the CsvParser class to parse the CSV file. I want to make the CsvReader class unit testable, so I want to be able to externally set the CsvParser class that is used (also, so you can create your own implementation). I also, don't want t...

Abstract factory pattern on top of IoC?

I have decided to use IoC principles on a bigger project. However, i would like to get something straight that's been bothering me for a long time. The conclusion that i have come up with is that an IoC container is an architectural pattern, not a design pattern. In other words, no class should be aware of its presence and the container ...

IOC/Autofac problem

I am currently using Autofac, but am open to commentary regarding other IOC containers as well. I would prefer a solution using Autofac if possible. I am also somewhat new to IOC so I may be grossly misunderstanding what I should be using an IOC container for. Basically, the situation is as follows: I have a topmost IOC container for m...

Castle Windsor or Spring.NET - advantages and disadvantages

Yesterday I was reading some articles in this site while I stumbled on an article about this two new IoC tools. Which one should I learn first? Is there some specification about which one should be used when? ...

Are IoC containers about configuration files?

Recently I developed a performance tester console application, with no UI, with the help of a IoC containter (Castle-Windsor-Microkernel). This library enabled me to let the user choose which test(s) to run, simply by changing the configuration file. Have I realized what IoC containers are about? I'm not sure. Even Joel said here on SO ...

Replace Spring.Net IoC with another Container (e.g. Ninject)

Hey all, I'm curious to know if it's possible to replace Spring.Net's built-in IoC container with Ninject. We use Ninject on my team for IoC in our other projects so I would like to continue using that container if possible. Is this possible? Has anyone written a Ninject-Spring.Net Adapter?? Edit I like many parts of the Spring.Net...

Dependency Inject (DI) "friendly" library

I'm pondering the design of a C# library, that will have several different high level functions. Of course, those high-level functions will be implemented using the SOLID class design principles as much as possible. As such, there will probably be classes intended for consumers to use directly on a regular basis, and "support classes" th...

Inversion of Control, Dependency Injection w/SRP, and Lazy-Loading

A fellow developer and I are conversing (to put it lightly) over Lazy-Loading of Properties of an object. He says to use a static IoC lookup call for resolution and Lazy-Loading of objects of an object. I say that violates SRP, and to use the owning Service to resolve that object. So, how would you handle Lazy-Loading following I...

Injecting Dependencies into Domain Model classes with Nhibernate (ASP.NET MVC + IOC)

I'm building an ASP.NET MVC application that uses a DDD (Domain Driven Design) approach with database access handled by NHibernate. I have domain model class (Administrator) that I want to inject a dependency into via an IOC Container such as Castle Windsor, something like this: public class Administrator { public virtual int Id { g...

Is there any way to add references without recompiling in .NET?

I am using a IoC Container (Castle Windsor) to instantiate classes accordingly to the configuration file. If I want to add classes from a new dll that didn't exist when I compiled the project, there is any way to do that without recompiling? Edit: As this project is a Service Host for WCF service, and the classes that I want to include ...

Best way to order menu items injected by an IoC/plugin Framework

One of the common things I've seen done in applications built on IoC/plugin frameworks is to add commands to menus or toolbars from the dynamically loaded plugins. For example, the application's default plugins supply actions like "New, Open, Save" that show up in the context menu for a certain item in the workspace. A new plugin may a...

ObjectContext never derives from an interface?? How do you apply DI/IoC in case of multiple types of ObjectContext?

If you have a system that has multiple types of object contexts. For Eg: BillingObjectContext, HumanResourceObjectContext etc. All derive from ObjectContext but ObjectContext Class does not implement any specific interface like IObjectContext. How would you apply DI/IoC in case of multiple types of ObjectContext say using Ninject? ...