ioc-container

Resetting an IKernel in Ninject v1

I am experiencing an issue with v1 of Ninject and resetting the StandardKernel. I have a static object that I use to provide access to the kernel like so public static class ObjectFactory { private static IKernel _kernel = new StandardKernel(new CanceisModule()); // Resolve methods snipped for brevity public static void ...

Dependency Injection and .NET Attributes

I have a couple of method attributes which do some logging. Our logging code sits behind an interface (ILog) and I'd like it if the attributes were only dependent upon that interface as opposed to an implementation. This isn't really about testability or dependency inversion so much as it is about keeping the coupling of components clean...

Why is Castle Windsor trying to resolve my 'Content' and 'Scripts' folder as a controller??

I have created an ASP.NET MVC application and am trying to use Castle Windsor as my IOC However, when the controllers are trying to resolve I am getting 'Content' and 'Scripts' into the 'controllerName' parameter in the CreateController(RequestContext requestContext, string controllerName) method. Needless to say these are not controlle...

Structuremap in VB .Net (WebForms)

I'm in the process of trying to hook StructureMap in to an existing webforms application. Since it's webforms I have to use Setter Injection, which is not ideal, but it's better than nothing. Where I'm coming unstuck is translating to VB (I'm really a C# dev currently working in a VB shop). I've written a custom scanner, which works fin...

Best way to use an IoC container for retrieving runtime settings

I have an C# dll project for which I have to store the runtime settings in an external XML file, and this dll will be used in an ASP.NET/ASP.NET MVC application for which I also have to store the runtime settings in a external file. Which IoC container can be used to create an object with the runtime settings loaded from a specific exte...

Castle IoC - ISubDependencyResolver that supports Release(...)?

Is it possible to build something that works like an ISubDependencyResolver but also supports Release(...)? I have a situation where I want to be able to resolve a derived class of Fruit in the constructor of a Blender: abstract class Fruit { } class AppleBlender { AppleBlender(Apple a) { } } Apple is unfortunately in a ...

Typical IoC container usage - passing data down the line

I've recently started using an IoC container for the first time, but I'm not educated on the best practices for using it. More specificaly I'm using Unity in a C# .NET project, and I started using it because it came with Prism. I use the container to resolve the "top level" objects, and they get the correct objects injected based on the...

AutoFac Autowiring Conventions

StructureMap has the ability to apply conventions when scanning. Thus IFoo => Foo, without explicit registration. Is something simular available in AutoFac? Looked around and just can't find anything helpfull. Thanks, ...

How can I use Windsor to inject a dependency into an ASP.NET MVC model?

I have a a model class that needs access to my repository class (used for DB access). I have created an interface for my repository and have successfully configured Castle Windsor to inject my the appropriate IRepository-based class into my controllers via a custom ControllerFactory. I'm having a little more trouble figuring out how to...

How do I use dependency injection with an ASP.NET MVC model?

I would like to inject a dependency into an ASP.NET MVC model, but I can't figure out where in the pipeline to do the injection. It's very straightforward with a ControllerFactory, but not nearly as much when dealing with models. ...

differences between IoC containers

I'm looking for some guidance about how to chose an IoC container for an ASP.NET MVC application. What are the differences between (for example) StructureMap, Ninject, Castle Windsor, Unity, autofac and others? Can anyone give some hints or links to resource that might help chosing one library? Update: there is one question (http://sta...

Dependency Injection Best Practises

I am using Dependency Injection in my code (with Ninject) and thought I was doing quite well until I came across a performance problem that was caused by a misunderstanding of where DI containers fit into your code. There seems to be a lot of information on how to use DI frameworks but not too much on where not to use them or how best t...

Besides DI, what benefits can I get from an IoC container?

IoC Frameworks just make DI much easier, but it's not only DI that they do, they provide a host of other benefits over and above DI. I saw this comment in one of the answers to a question about DI and IoC. Can someone explain this in some more details? What are other benefits of IoC? ...

Constructor on type: "Namespace.type" not found.

Hello, I am using Castle.Windsor as an IOC. So I am trying to resolve a service type in the constructor of an HTTPHandler. I keep receiving this error, "Constructor on type: "Namespace.type" not found." My configuration has the following entries for service type: IDocumentDirectory <component id="restricted.content.directory" service=...

Castle Windsor Interceptor for private/protected method

Hi all, Is it true that in order for castle windsor's interceptor to intercept a method, that method needs to be declare public? ...

Why is this method call not getting intercepted?

Why doesn't DoIt() method call get intercepted? Should I use something other than InterfaceInterceptor to intercept the DoIt() method? How would you do it? using System; using Microsoft.Practices.Unity; using Microsoft.Practices.Unity.InterceptionExtension; namespace UnityTest { class Program { static void Main(string[] ar...

Resolving a Generic with a Generic parameter in Castle Windsor

I am trying to register a type like IRequestHandler1[GenericTestRequest1[T]] which will be implemented by GenericTestRequestHandler`1[T] but I am currently getting an error from Windsor "Castle.MicroKernel.ComponentNotFoundException : No component for supporting the service " Is this type of operation supported? Or is it to far removed ...

Should I use Castle Windsor because NHibernate is using it, and I'm already using NHibernate?

I've just finished converting a large amount of legacy code to use NHibernate. The next thing I want to do is introduce an IOC container for hooking up the data access layer repositories and other such things. There are a variety of options out there at the moment - Castle Windsor, StructureMap, NInject, Unity etc; the choice is difficul...

How can I override a component registered in Castle Windsor?

I'm just starting with Windsor, so please be gentle :) I have a scenario where I want to be able to override/replace components placed inside a windsor container. Read on ... In my prod code, I want to be able to register a component which implements a base class, and use a container to resolve the implementer. So far, using container...

NServicebus Message Handler Lifecycle in IOC StructureMap

What is the required IOC instance lifecycle I need to use in conjuction with a NServiceBus message handler if I want an instance per message handled. PerRequest won't work, since given the numerous constructor dependenices and dependency graph I have, it gives me many instances when I require only one per Handle(MessageX msg) call. I ca...