inversion-of-control

Examples of ASP.Net MVC 2 - WCF/WSDL - using IoC methodology

We here at my company are just about to get going on ASP.Net MVC 2 for our UI to interface a backend totally SOA with WCF/WSDL. I have looked at various books examples of how to totally make the applicalion loosely coupled from the Domain perspective using the IoC containers e.g. Unity or Castle (looks to be the way to go !) ...BUT Are t...

How can I use some kind of IoC (?) to automatically register routes for my ASP.NET MVC controllers?

Currently I've found that it's most convenient to have a separate public static void RegisterRoutes(RouteCollection routes) method on each of my controllers. Then in Global.asax's RegisterRoutes, I call all of these methods. Of course, this is quickly getting out of hand. Every time I add a new controller, I have to go and update Regist...

Override a protected internal virtual method in c#

I am trying to build a class like so... public class IoCControllerFactory : DefaultControllerFactory { protected override IController GetControllerInstance(RequestContext request_context, Type controller_type) { // Attempt to resolve controller type. IController resolvedControll...

How do I resolve an array with Unity and pass a parameter to one of the items in the array?

Hi there, So here's my factory method which takes a parameter... container.RegisterInstance<Func<IProductInstance, IQuantityModifier[]>>( instance => container.Resolve<IQuantityModifier[]>()); Now one of the items returned by the array takes the IProductInsance parameter in its constructor. I can't figure out ...

Basic Ninject Information required please.

I've been slowly teaching myself the fundamentals of interface driven programming and I'm struggling to get my head round a few principles regarding inversion of control specifically with Ninject. Lets say I have a concrete model class as follows... public sealed class Host : EntityAuditable<Host, Guid> I have a base class which def...

How to have structuremap build instance based on type.

Ok so this might not be the best title but I am struggling with how to title this. Here is what I have thus far: I currently have data mappers for my objects. I define them in a registry like so. This allows me to get the type name of the object and combine that with the word Mapper and request it. Here is the code I am using: this.For...

MEF error, was circular dependency and is now something else...

I've got a circular dependency that recently came about because of a change in my application architecture. The application relies on a plugin manager that loads plugins via MEF. Everything up until worked fine, because it looked something like this: // model.cs [Export("Model")] public class Model { public PluginManager PM { get; s...

What is the best way of using NLog with MEF?

Hello, I am wondering what is the best way to use NLog with Managed Extensibility Framework (MEF)? I have an application that support plugins using MEF architecture (Import and Exports etc) I want to add logging capability to my application. As a logging component I want to use NLog. What would you recommend? 1. Create a wrapper for N...

Create instances of a class that needs a constructor argument with StructureMap

I have the following classes: public class AllowanceManager : IAllowanceManager { public AllowanceManager(ITranslationManager t_Manager, ISessionManager s_Manager) {...} } public class TranslationManager : ITranslationManager { public TranslationManager(string culture) {...} } public class SessionManager : ISessionMan...

Is this the correct way to instantiate an object with dependencies from within a Domain Model?

I'm trying to avoid ending up with an anaemic Domain Model, so I'm attempting to keep as much logic as possible within the domain model itself. I have a method called AddIngredient, which needs to add a new KeyedObject to my Recipe Aggregate. As the Domain Models themselves are meant to be devoid of repositories, I'm getting the ingredi...

How to avoid cyclic behaviour with Castle Windsor's CollectionResolver?

I am using Castle Windsor 2.5 in my application. I have a service which is a composite that acts as a distributor for objects that implement the same interface. public interface IService { void DoStuff(string someArg); } public class ConcreteService1 : IService { public void DoStuff(string someArg) { } } public class ConcreteServi...

How do I use Common Service Locator in Ninject 2

Changes in Ninject 2 say that Ninject support Common Service Locator, but how do I use it? I don't find any manual or sample. ...

IoC (StructureMap) Best Practice

By my (likely meager) understanding, doing this in the middle of a method in your controller / presenter is considered bad practice, since it creates a dependency between StructureMap and your presenter: void Override() { ICommentForOverrideGetter comm = StructureMap.ObjectFactory.GetInstance<ICommentForOverrideGetter>(); since th...

Licensed component not playing well with DI design

We've licensed some third-party e-mail components and have developed a set of components for our system that uses them. These components are then loaded dynamically at runtime by an IoC container. However we have recently noticed in testing on a non-development machine that because the main .EXE which is "hosting" our components does no...

Custom principal in ASP.NET MVC

I want to be able to access custom properties for an authenticated user like UserId and FirstName without querying the database each time. I found this site through a post on Stack Overflow and I like the approach - but I use IoC / repositories and decided not to try and get global.asax to communicate with the database for fear that it ...

StructureMap IOC named instances help.

Hi, Having a problem with StructureMap IOC. I wish to retrieve different concrete implementations of objects that implement the same interface based on labels or names. internal static class InstanceHelper { internal enum Taxonomy { Foo, Bar } static InstanceHelper() { // Initialize th...

how to create a Spring bean from a static inner class constructor?

I am trying to use the Spring Framework IoC Container to create an instance of class ThreadPoolExecutor.CallerRunsPolicy. In Java, I'd do it this way... import java.util.concurrent.RejectedExecutionHandler; import java.util.concurrent.ThreadPoolExecutor; ... RejectedExecutionHandler rejectedExecutionHandler = new ThreadPoolExecutor.Cal...

Automapper Custom Resolver - Inject Repository into constructor

I am trying to create a custom resolver for automapper which needs to access one of my data repositories to retreive the logged in users account. Here is my code so far... public class FollowingResolver : ValueResolver<Audio, bool> { readonly IIdentityTasks identityTasks; public FollowingResolver(IIdentityTasks ide...

How can i initialize some Dependency Injected instance?

Hi folks, I'm using StructureMap DI/IoC and I've got is a generic InMemory repository. Works great. I was wondering if it's possible to define the initial data which each repository holds, when it's requested? Now, the first reaction is to do this in the constructor of the class - but I'm using a Generic Repository .. so i don't know w...

Does unity just make clasess with out needing anything registered?

I am watching Mike Tautly's awesome intro to Prism. It was all making sense, but I got a bit confused in the sixth video. He has his view class's constructor take a parameter of the ViewModel. He then says that unity will fill this in for us (ie construct it). In the past he has had to register this kind of thing (ie IMyClass registe...