ioc-container

Which single IoC/DI container would you recommend using and why?

I'm asking this question because it's a good way to gauge how the community at large feels about the various containers/frameworks and why. Also, whilst my expertise may lie in .Net development, I am very interested in which frameworks are popular (and why) in other languages. If I feel the need to start digging into Java for instance, t...

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 to inject a changing dependency

I'm new to dependency injection, I'm wondering how you would handle the following scenario. We have something like the following: public class DatabaseContext { public string ConnectionString {get;} } public interface IDataAccess { string GetString(int id); } public class DataAccessImpl : IDataAccess { private DatabaseContext _...

IoC Container Applicability / Scenario Demonstration?

A lot of people in the .NET space have picked up Castle Windsor and are implementing it in their projects, and for the past year I've been struggling to figure out why IoC containers seem to be treated as general "best practice"? I've read a LOT of abstracts and brief explanations on the why's of Windsor and the like, but every last one ...

.NET - What IoC Container framework would you recommend to a beginner in this area?

What Inversion of Control Container framework would you recommend to a beginner in this area? ...

Binding to multiple concrete implementations with IOC frameworks?

I'm relatively familiar with the concepts of DI/IOC containers having worked on projects previously where their use were already in place. However, for this new project, there is no existing framework and I'm having to pick one. Long story short, there are some scenarios where we'll be configuring several implementations for a given in...

How can I dispose every instance object in StructureMap's ObjectFactory?

I'm using StructureMap in my project and when the application finishes running I need to call the Dispose() method on all of the instances inside the ObjectFactory that implement IDisposable. I cannot find anyway to do it via the StructureMap API. Another thought I had was to get a reference to every instance and call it myself, but I ...

Code your own IOC Container

Has anyone out there written their own IOC Container in C#? Or do the vast majority of folks use the various frameworks such as Spring. What are the pro's and con's of each? ...

Can I create IOC controls using .NET to be placed in web projects?

I currently have a library of UserControls which I use in a lot of our web applications. I would like to update these controls so that I can use IOC to help seperate the logic. So I would have something similar to the following on the web page itself: <prefix:ControlName ID="myControl" runat="server" property="value1" /> And the cont...

Castle Windsor - One class implementing multiple interfaces

I register my two interfaces on application start as so:- container.Register(Component.For(typeof(IEntityIndexController)).ImplementedBy(typeof(SnippetController)).LifeStyle.Transient); container.Register(Component.For(typeof(ISnippetController)).ImplementedBy(typeof(SnippetController)).LifeStyle.Transient); Then when I try to run an ...

Unittesting IoC registration?

Should you unittest the code that registers components into your IoC container? If so, how? ...

How to resolve instances with constructor parameters in custom IOC Container?

I'm trying to build my own inversion of control container. Right now I store the objects with their types in a dictionary and resolve a reference when asked. But I want to make it possible to resolve a reference or a new instance. I can create a new instance with the Activator class. But, what if the constructor of the object to resolve...

How does Castle Windsor respond to a class which implements multiple interfaces?

For example I have two interfaces: ICustomerService and IOrderService which each has a couple of functions like GetCustomer, GetOrder, etc. I want one class to implement both interfaces: Server. How does Castle Windsor respond to this? Is it possible in the first place? When I resolve the Server object based on one of the two interfac...

What are the pros and cons for using a IOC container?

Using a IOC container will decrease the speed of your application because most of them uses reflection under the hood. They also can make your code more difficult to understand(?). On the bright side; they help you create more loosely coupled applications and makes unit testing easier. Are there other pros and cons for using/not using a ...

IoC and events

I am having a really hard time reconciling IoC, interfaces, and events. Let's see if I can explain this without writing a book. I'm just getting started with IoC and I'm playing with Spring. We have a simple data layer that was built long before EF or the others. One of the classes is a DBProcedure which has some methods and events. I ...

Not understanding where to create IoC Containers in system architecture

Hi, Say I have the following 4 .net assemblies: Winforms UI Business Logic SQL Server Data Access (implementing an IRepository) Common Interfaces (definition of IRepository etc.) My business logic (2) makes calls to the data access layer (3) through IRepository (defined in 4) using constructor dependency injection. However when I ...

Setting PerWebRequest Lifestyle In NHibernate

I have a pretty basic NHibernate setup. I am not using Castle Widnsor or anything special like that to do IoC in my code. All I want to do is set my Lifestyle to PerWebRequest, but I cannot figure out how to do this with out going back through my code and updating it to use an IoC library. Is there any way to do this in the config f...

NInject: Where do you keep your reference to the Kernel?

I'm using NInject on a new web application and there are two things that are unclear to me: Don't I need to keep a reference to the Kernel around (Session/App variable) to insure that GC doesn't collect all my instances? For example, if I specify .Using() and then the Kernel object gets collected, aren't all my "singletons" collected ...

Microsoft Unity - code to xml

Can someone provide the XML configuration I should use with Microsoft Unity application block in the Enterprise Library 4.1 to achieve the same result as the following? using System; using Microsoft.Practices.Unity; using Microsoft.Practices.Unity.InterceptionExtension; namespace ConsoleApplication1 { class Pr...

How to overwrite a component with castle windsor?

I want to redefine an (default) implementation in a given windsor-container. Is that what OverWrite is for? Doesn't work, though. container.Register( Component.For<IServiceOperationAuthorization>() .OverWrite() .Instance(_authorization) ); ...