inversion-of-control

Inversion of control for return object

I have a method returning an ISomething. I am trying to use Inversion of Control throughout my program... but I have no idea how to do it when it comes to the return value - I cannot pass it to the method, or to the object when constructing it, because this method is supposed to create the object. The only solution I see is to pass an I...

Structuremap Scope/Lifecycle Guidance?

Is there any reason to switch from the default scope (transient?) to something else, outside of needing to control the scope for functional reasons (e.g. Singleton)? If I stick with the default scope, every default instance of every plugin type will effectively get instantiated on each request (assuming a web app), is that correct? Can...

ASP.NET MVC - Sharing Session State Between Controllers

I am still mostly unfamiliar with Inversion of Control (although I am learning about it now) so if that is the solution to my question, just let me know and I'll get back to learning about it. I have a pair of controllers which need to a Session variable, naturally nothing too special has happen because of how Session works in the first...

Integrating ASP.NET-MVC with Silverlight using WCF and Ninject as IoC/DI

I have a prototype ASP.NET-MVC website which uses Ninject as a IoC container. All service-classes and repository-classes used by MVC Controllers are properly injected by Ninject. This is great. The next thing I need to add there is Silverlight (version 3 to be more precise). Silverlight will be connecting to my server using WCF service,...

Ninject kernel binding overrides

I'm just wondering what the best practice is for rewiring the bindings in a kernel. I have a class with a kernel and a private class module with the default production bindings. For tests I want to override these bindings so I can swap in my Test Doubles / Mocks objects. does MyClass.Kernel.Load(new InlineModule(m=> m.Bind<IDepend>(...

Get instance conditionally in StructureMap

Hi, I have an interface IFileSystemStructureEvaluator with two concrete implementations: NtfsFileSystemStructureEvaluator and FtpFileSystemStructureEvaluator. I want to be able to request the appropriate IFileSystemStructureEvaluator depending on whether the Uri that is passed to the constructor is a file uri of an FTP uri. How can I ...

dependency browser that runs against an inversion of control framework

Do any inversion of control / dependency injection framworks support viewing the object dependencies that have been registered? This is not to execute the code, but to better understand it. It seems that a graph based on the information it has (class A depends on B and C, class B dependencs on C and E, etc) would really document a syst...

What should I consider when choosing a dependency injection framework for .NET

see also Which C#/.NET Dependency Injection frameworks are worth looking into? There are now many dependency injection frameworks to choose from. You used to often be forced to use a given dependency injection framework due to a library you were using. However the Common Service Locator library has enabled library code to be i...

When is Inversion of Control useful and when shouldn't it be used?

I've recently been bitten by code that uses Inversion of Control when it's not appropriate. Lately, I'm of the opinion that IoC is among the patterns that have the worst effect when misapplied. This is because it tends to create a coupling of classes that can cause a lot of shotgun surgery if you run into a circumstance that's a little...

Castle IoC - How can I prevent registered components being resolved as dependencies?

I'm using the method described by Bojan Resnik in this question to resolve instances of classes that are not registered in the Windsor container. The problem is that I don't want these classes to be available as "services" to other resolved instances. For example, given the following classes: class Order { public Order(ITaxCalculat...

MEF vs. any IoC

Looking at Microsoft's Managed Extensibility Framework (MEF) and various IoC containers (such as Unity), I am failing to see when to use one type of solution over the other. More specifically, it seems like MEF handles most IoC type patterns and that an IoC container like Unity would not be as necessary. Ideally, I would like to see a ...

Do Extension Methods Hide Dependencies?

All, Wanted to get a few thoughts on this. Lately I am becoming more and more of a subscriber of "purist" DI/IOC principles when designing/developing. Part of this (a big part) involves making sure there is little coupling between my classes, and that their dependencies are resolved via the constructor (there are certainly other ways o...

Struggling with runtime setup of some castle components

My question (I think) can be simply described by this question: How can I get a "Manager" class to have a list of all possible concrete implementations of a specific interface that have been registered as components injected into it so it can iterate through them? (And because of annoying architecture reasons I can't use the app.config ...

S#arp architecture vs straight IOC + NHibernate + MVC

Are the benefits enough to use another external assembly? How difficult is it to remove S#arp and keep NHibernate at a later point? ...

Logging framework being injected into classes

Should a logging framework be injected into classes that need them or should every class that needs it just know the framework and use it directly? I am using Log4Net and currently I am injecting a service that wraps that framework into the classes that need to be able to log, knowing logging is probably not going to change and that mos...

How can you generically map a DbDataReader to a Castle.Windsor resolved type?

This is confusing me, so this question will probably be confusing. I have a an application that uses implementations of an IJob interface to accomplish different tasks. public interface IJob { int Id { get; set; } string Name { get; set; } void Run(); } I am using the Castle.Windsor.WindsorContainer to resolve these implementa...

ASP.NET MVC - Ninject 2.0 Activation Error

I just started working with dependency injection for the first time and I am using as Ninject 2.0 as my IoC container in an ASP.NET MVC 2 website and I'm hitting an activation error that I am not sure how to react to. I am sure it's simple so hopefully someone can point me in the right direction without too much thought. I have a proper...

Should I use DuplicateKeyException in my own non-LINQ code?

I'm writing an auditing service for some business-critical operations. The service is being implemented using the IoC pattern: public interface IAuditWriter { void WriteAction(int key, string value); } Because of this, I need it to raise exceptions which are not specific to the implementation. Part of the information in the audi...

Structure Map Registry DSL Override

Is there an equivalent xml configuration for StructureMap's Registry DSL configuration: ForRequestedType<T>().TheDefaultIsConcreteType<T>(); There is some limited documentation around Structure Map's XML Configuration on the SM site, but I have yet to get any XML configuration items to override Registry DSL entries. Is there a way ...

What design pattern to locate my IUnitOfWork?

I've implemented a repository pattern with persistence ignorance. The repository implementation only interacts with my entity objects, IUnitOfWork and ITable<T> interfaces. The intention is that the IUnitOfWork isn't reused but represents a single transaction. So far, I've implemented in-memory as well as Linq-to-Sql versions of the IUni...