inversion-of-control

AOP x IoC for caching

Do you prefer the clean approach of an AOP cache layer on top of your methods (any DAO or service method) OR do you prefer the total control approach of injecting a cache instance wherever you need? I understand AOP gives you loose coupling and separation of concerns, but not so much flexibility, unless you are coding the method interce...

Alternative to TheDefault and ConstructedBy methods in Unity

Basically what i'd like to do is injecting what's in HttpContext.Current.User everytime I ask for an IPrincipal. This is the code in StructureMap: ForRequestedType<IPrincipal>() .CacheBy(InstanceScope.Hybrid) .TheDefault.Is.ConstructedBy(ctx => HttpContext.Current.User) How do I achieve the same in Unity?. ...

Spring bean fields injection

Using Spring IoC allows to set bean properties exposed via setters: public class Bean { private String value; public void setValue(String value) { this.value = value; } } And the bean definition is: <bean class="Bean"> <property name="value" value="Hello!"> </bean> Is there any existing plugins/classes for S...

How to set a default constructor argument to null with StructureMap?

A class has a unique constructor taking IMyInterface as its argument. If I define a concrete type of IMyInterface and registers it to StructureMap then there is no issue and my class can be instanciated with this concrete type. However, in some cases, no concrete type will be registered. In that case, I would like to receive null for th...

Ninject.Web (webforms extension), injecting outside of a webform page?

I've been using the Ninject.Web extension to inject business objects, repositories, Entity Framework context etc into my application. This works very well using the [Inject] attribute which can be applied within a webform that inherits from PageBase. I am now running into a snag as I am trying to write a custom membership provider that...

Autofac - Service constructor takes reference to instantiating object.

How do I deal with: Current code looks like; class Class1 : ISomeInterface IFooService _service; void SomeMethod(){ _service = new FooService(this); ..... } class FooService : IFooService public FooService(ISomeInterface class1Implementer) { _class1Implementer = class1Implementer } I want...

Ninject.Web.Mvc add-on not working with ASP.NET MVC 2

I'm using the Ninject.Web.Mvc (the MVC 2 version) add-on with ASP.NET MVC 2. This is an excerpt of my Global.asax.cs: protected override void OnApplicationStarted() { AreaRegistration.RegisterAllAreas(); RegisterRoutes(RouteTable.Routes; // RegisterAllControllersIn() is not available in the MVC 2 version of Ninject } protec...

Can anyone recommend an IoC container for ASP.NET 2.0 Webforms?

As the title says, I'm looking for recommendations for an IoC container to use with an ASP.NET 2.0 Webforms app. I believe that some containers are .NET3.5 or newer only. ...

Unity IoC and MVC 3 Beta - Passing IRepository to Controller Constructor

Did something change in MVC 3? I have tried all the examples on the Internet for setting up Unity as my IoC Container, but I keep getting an error saying that Unity cannot resolve my UserController. Here is my constructor on my UserController: public UserController(IUserService userService) { _userService = userService; } I have...

Why IOC is outdated according to MSDN ?

It is said here: http://msdn.microsoft.com/en-us/library/ff921087.aspx ...

Castle Windsor DynamicProxy Interception IInvocation Documentation

On a Castle Castle.DynamicProxy.IInvocation, what's the difference between GetConcreteMethod GetConcreteMethodInvocationTarget Method I read the documentation, but I don't understand the difference, especially between the first two. I'm guessing that Method is just the MethodInfo for the method on the actual registered type? ...

IoC and ASP.NET MVC, where does it all begin?

I see "IoC" and "DI" mentioned pretty much everywhere for ASP.NET MVC. While I'm well aware of ... 'kind of' what these are, it's one of those almost ambiguous, amorphous floating concepts that seems to have either passed me by, or I'm just not looking in the right place. With the upcoming release of ASP.NET MVC 3.0, I'm seeing it even m...

Development and deployment - how to get service assemblies into their proper location?

Hi, This has to be a pretty common issue, and while we have answers, I'm trying to determine if there is any better way. We are using IoC / DI with structuremap. This means that our final application (an Asp.Net MVC 2 app) requires the presence of some assemblies which aren't being referenced anywhere else (our implemention of IReposi...

Castle Windsor Internal Constructor/Class

I looked at this and it answers half my questions: http://stackoverflow.com/questions/2370546/castle-windsor-register-class-with-internal-constructor But can you use Windsor to use internal constructors/class along with dependency injection? (so constructor parameters get injected too)? I'd like to keep the class/constructor internal t...

Windsor Registration Child Container Visibility

I have some (sort of) Singletons which exist in three context: Per AppDomain Per HttpApplication Per Web Request Right now, I'm creating a child container per HttpApplication and another child per Web Request. This is necessary because some components SHOULD actually share singleton instances across the three layers. For security and...

Is "program to interfaces" a common design principle in C++ projects?

I read a lot about "program to interfaces" and "inversion of control" during the last days. Mostly in the context with the Java language. My question is if it is also a common practice in C++ development. What are the advantages? What are the disadvantages? Is it worth to apply to small projects (like 15-20 classes)? ...

Windsor Interceptor Exception

I have a Windsor container that I'm using an InterceptorSelector and a LazyComponentLoader with. My InterceptorSelector returns an InterceptorReference to my InterceptorAdapter class that looks like this public class InterceptorAdapter<T> : Castle.DynamicProxy.IInterceptor, IOnBehalfAware where T : IMyType { private readonly T int...

Does the Common Service Locator support Mono .NET?

Does the Common Service Locator, used for "providing an abstraction over IoC containers and service locators", support Mono .NET? ...

Tell C# to use Castle to create objects

Hi! I think my question is a long shot. Lets say I have an attribute: public sealed class MyCustomAttribute: ActionFilterAttribute Used on a class method [MyCustomAttribute] public virtual ActionResult Options(FormCollection collection) Now, I need to add a contructor's parameter public MyCustomAttribute(IMyDependent...

Castle Windsor - single place for component install?

After reading the documentation (http://stw.castleproject.org/Windsor.Installers.ashx) I've found a strange part: Although technically it's OK to call Install multiple times, or register components outside of installers it is considered good practice to encapsulate all registration in installers, and to install all installers during ...