inversion-of-control

How to programmatically register a component that depends on a list of already registered components with Castle Windsor?

I'm programmatically registering a group of services that all implement the same interface, IRule. I have another service that looks like this: public class MyService { private IEnumerable<IRule> _rules; public MyService(IEnumerable<IRule> rules){ _rules = rules; } } Hammett posted something that looked like what ...

Yet another AoP vs IoC/DI Question

Hello, I'm stuck and I'd appreciate your opinions on the subject. I want to implement INotifyPropertyChanged for my entities. I can't figure out which way is the best and why. The only obvious difference to me is that AoP is a little faster since everything gets done at compile-time while using IoC/DI it's easier to change behaviors lat...

IOC on IValidationDictionary with Castle Windsor

I'm new to Castle Windsor and am just using the latest version. I've created entries for my repositories which are working fine but I have one final dependency that I'm passing into my controller. I've created a ModelStateWrapper which inherits from IValidationDictionary. The ModelStateWrapper takes a ModelStateDictionary in it's constr...

Resolving constructor paramters using the same name used for resolving the object

Say I have this class public class MyObject : IObject { public MyObject(IObject2 object2) { } } which I resolve like: Container.Resolve<IObject>("SomeName"); Is it possible to configure Unity so that whenever an IObject is resolved using any name, then the IObject2 will also be resolved with that same name (assuming ...

When is it appropriate to take a direct dependency on the IoC container itself?

I'm just about to create a WorkQueueService that can handle different type of WorkItems. For each type of WorkItem, I will have an implementation of IWorkItemProcessor. I'm using IoC, so all the IWorkItemProcessor implementations will be registered in the container. My WorkQueueService will need to obtain the appropriate Processor for ea...

Using Ninject IOC to replace a factory

I've got a factory method inside a parser. Essentially as I load a token I look up the handler for that token, or drop through to the default handler. I've implemented this as a switch and as a Dictionary<string,Type> but both approaches require me to store the mapping somewhere else than the handler class. We are using Ninject for IOC ...

How to handle injecting dependencies into rich domain models?

In a web server project with a rich domain model (application logic is in the model, not in the services) how do you handle injecting the dependencies into the model objects? What are your experiences? Do you use some form of AOP? Like Springs @Configurable annotation? Load time or build time weawing? Problems you encountered? Do you u...

Using a factory in an domain model object?

Scenario: In my application (which utilises an rich domain model, where the logic is in the model, not in the services) I have users. I create new users with a service User newUser = userService.createNewUser("Hans Dampf"); or get them from the database User oldUser = userDao.findByName("Hans Dampf"); Because in every call into my...

IoC and constructor over-injection anti-pattern resolution

This question is a result of a post by Jeffery Palermo on how to get around branched code and dependency injection http://jeffreypalermo.com/blog/constructor-over-injection-anti-pattern/ In his post, Jeffery has a class (public class OrderProcessor : IOrderProcessor) that takes 2 interfaces on the constructor. One is a validator IOrder...

How can I debug code like CodeCampServer, that is based on Depedency Injection?

My project structure is like CodeCampServer structure, etc. UI.dll, Core.dll and DependencyResolution.dll that have a dependecy of both of UI.dll and core.dll. In the web.config I use a HttpModules from the DependencyResolution.dll, to instantiate all the dependencies, and therefore I can't run this application in VS2008 because the UI....

StructureMap: How to set lifecylce on types connected with ConnectImplementationsToTypesClosing

In my registry I have Scan(scanner => { scanner.AssemblyContainingType<EmailValidation>(); scanner.ConnectImplementationsToTypesClosing(typeof(IValidation<>)); }); What am I supposed to do to define these all as Singletons? Also as an aside to this question, is there any reason to not defin...

Android and Dependency Injection

I've been looking around, in vain, for some information on using a dependency injection container in Android development. Specifically, how to override the creation of an Activity in a way that will also work when coming back from being killed (for whatever reason). Has anyone got any experience in this area? ...

StructureMap InstanceInterceptor not being called...

I want to intercept the creation of an instance in SM and I'm trying the following but it's not calling the InstanceInterceptor implementation, does anyone know why? ForRequestedType<IPublishResources>() .TheDefault .Is .OfConcreteType<PublisherService>() .InterceptWith(new PublisherServiceInterceptor()); The test code uses the Ob...

Dependency injection in .Net without virtual method calls?

I've been thinking about whether it's possible to apply the DI pattern without incurring the cost of virtual method calls (which according to experiments I did can be up to 4 times slower than non-virtual calls). The first idea I had was to do dependency injection via generics: sealed class ComponentA<TComponentB, TComponentC> : ICompon...

Injecting Lower Layer Dependency in Presenter in an ASP.NET MVP Application

I recently read Phil Haack's post where he gives an example of implementing Model View Presenter for ASP.NET. One of the code snippets shows how the code for the view class. public partial class _Default : System.Web.UI.Page, IPostEditView { PostEditController controller; public _Default() { this.controller = ne...

Is this a problem typically solved with IOC?

My current application allows users to define custom web forms through a set of admin screens. it's essentially an EAV type application. As such, I can't hard code HTML or ASP.NET markup to render a given page. Instead, the UI requests an instance of a Form object from the service layer, which in turn constructs one using a several RDM...

StrcutureMap Wiring - Sanity Check Please

Hi - Im new to IOC and StructureMap and have an n-level application and am looking at how to setup the wirings (ForRequestedType ...) and just want to check with people with more experience that this is the best way of doing it! I dont want my UI application object to reference my persistence layer directly so am not able to wire everyt...

Inversion of Control / Dependency Injection with good explanation and examples in .net?

Hi I don't have much knowledge on IoC/DI frameworks in .net framework. Can anyone give me links that explans IoC/DI in detail with few example in C#? I want go through it and get more idea about these frameworks. So that I can get the knowledge, where and How can I use these frameworks are useful in implementing the project. Thanksnrk ...

IoC.Resolve vs Constructor Injection

I heard a lot of people saying that it is a bad practice to use IoC.Resolve(), but I never heard a good reason why (if it's all about testing than you can just mock the container, and you're done). now the advantages of using Resolve instead of Constructor Injection is that you don't need to create classes that have 5 parameters in the...

Keeping the DI-container usage in the composition root in Silverlight and MVVM

It's not quite clear to me how I can design so I keep the reference to the DI-container in the composition root for a Silverlight + MVVM application. I have the following simple usage scenario: there's a main view (perhaps a list of items) and an action to open an edit view for one single item. So the main view has to create and show th...