inversion-of-control

Windsor Fluent Interface Lifestyle

Are these equivalent syntaxes for setting component lifestyle? Component.For<IFoo>() .ImplementedBy<Foo>() .LifeStyle.Is(LifestyleType.Transient) Component.For<IBar>() .ImplementedBy<Bar>() .LifeStyle.Transient ...

Problems with MVC Controllers + Dependency Injection (Ninject) in medium trust

I want to use dependency injection in an medium trust environment. To that aim I picked Ninject as Iv been told its light weight. How do I set-up injection into the controllers? When I tried to create a custom controller factory: public class NinjectControllerFactory : DefaultControllerFactory { private readonly IKernel...

IoC/DI framworks with Smart Client Winform apps: How should I approach this?

I'm starting a new Winforms app, and I intend to use an IoC/DI framework (probably Ninject, but i'm also thinking about StructureMap and LinFu). It seems like nearly everyone who is using IoC/DI is doing so in a web based environment and have found virtually nothing on using Winforms with it. I'd like to know if anyone is using IoC/DI ...

Registering Types at Runtime

I'm trying to figure out how to register a type at run-time using unity. Any Suggestions? Basically I want to be able to do this: Container. RegisterType(Of IMyInterface)( Type.GetType("Fully Qualified Type Name")) ...

Inversion of Control, Spring Framework - system of global instances

Is inversion of control essentially just retrieving a set of already instantiated objects? In theory. I guess more granular details as implemented by IoC frameworks like Spring have a lot more functionality, but in theory it seems like IoC containers operate like a collection of instantiated beans (in the Java world) and then you get a...

Interface Insanity

I'm drinking the coolade and loving it - interfaces, IoC, DI, TDD, etc. etc. Working out pretty well. But I'm finding I have to fight a tendency to make everything an interface! I have a factory which is an interface. Its methods return objects which could be interfaces (might make testing easier). Those objects are DI'ed interfaces to t...

Generic Type in constructor

I have a Generic Type Interface and want a constructor of an object to take in the Generic Interface. Like: public Constructor(int blah, IGenericType<T> instance) {} I want the code that creates this object to specify the IGenericType (use Inversion of Control). I have not seen a way for this to happen. Any suggestions to accomplish...

Resolve externally created object instance with no public constructor

Using the adapter pattern, combined with IoC (specificly Unity), I would like to create a new instance of a object of which the properties point back to the adaptee's propeties (basicly mapping the adaptee to a target object). As a example I have the following class structures: public class Adaptee { private Adaptee() { } publ...

Simple Spring, use of ClasspathApplicationContext for standalone apps, how to reuse?

If I have a standalone main application. Say 20 classes. They all may need to interface with the beans defined by the spring configuration (ApplicationContext) at any time. I would boostrap the classpath application context at the main application entry point. But how do you reuse the already instantiated beans? For example, it seem...

Spring.NET & Alternatives

Is Spring.NET a good framework to use in web development? Are there alternatives? Update (for Frederik): Are there drawbacks when using Spring.NET (or IoC container) in Web Development. I always used spring.actionscript in client side flex applications, but client applications aren't the same as Web Applications. Is there a Microsoft...

Using Ninject (or some other container) How can I find out the type that is requesting the service?

Suppose I have an interface for a service: public interface IFooService { void DoSomething(); } And a concrete implementation of that service that is a generic: public class FooService<TRequestingClass> : IFooService { public virtual void DoSomething() { } } And I have some other class that needs an instance of IFooService: ...

Automated tests: mocking vs creating test object graph ( using IoC container), what is better under what conditions?

How do you decide what to choose: use mock objects for a test OR create a test object/ object graph using an IoC framework and run test on that data ...

Refactoring a method having dependencies within the same object into something more testable (PHP)

I currently have a method within my class that has to call other methods, some in the same object and others from other objects. class MyClass { public function myMethod() { $var1 = $this->otherMethod1(); $var2 = $this->otherMethod2(); $var3 = $this->otherMethod3(); $otherObject = new OtherClas...

When would you use the Common Service Locator ?

I've been looking at the Common Service Locator as a way of abstracting my IoC container but I've been noticing that some people are strongly against this type of this. Do people recommend never using it? Always using it? or sometimes using it? If sometimes, then in what situations would you use it and what situations would you not use ...

How to perform property injection with Unity and asp.net mvc on action filters?

I am trying to get dependency injection working on my action filters with property injection. I can't figure out how to automatically set dependencies on the filters. Here is the code I have so far. public class UnityActionInvoker : ControllerActionInvoker { IUnityContainer container; public UnityActionInvoker(IUnityContainer ...

With Autofac what would be the advantages and disadvantages

I've read about Autofac that it's fast. I've seen the coding involved and it's preatty neat. But I'm not quite sure how to use it. I've used StructureMap, and it has a static ObjectFactory. Ninject has the Kernel, but in autofac's google pages they recomend doing something like this : using( var resolver = builder.Build() ){ var wh...

Structuremap 2.0 documentation

I'm just starting to learn DI/IOC methods and like what I see so far from Structuremap. The problem is that my current project is limited to .NET 2.0 so I cannot use the new version (2.5) of Structuremap. That being said, can someone point me towards some documentation for v2.0? Most articles and tutorials use v2.5 and only a small fe...

How would you modify this function to IOC?

Hi, I have a simple function, just want an idea of how I would convert my coding style to IOC. public User GetUserByID(int userID) { DataProvider dp = new DataProvider(); return dp.GetUserByID(userID); } my dataprovider is simple ADO.net, it opens a connection, calls the sproc and returns the User object. ...

Enforcing dependencies in IoC via a constructor?

I'm trying to come to terms with using IoC/Dependency Injection while at the same time programming to contracts rather than specific classes. The dilemma I'm having is the tension between: Do program to interfaces for IoC: I started out with IoC relying heavily on interfaces. Judging by Spring's sample projects, interfaces are the way ...

WPF + IoC: "Specified Visual is already a child of another Visual or the root of a CompositionTarget."

[Edit: Rethinking architecture along mvvm lines made this problem largely fall away - thanks @kent] Using Spring.NET + WPF. Load two WPF buttons in the config: <object name="Button1" type="System.Windows.Controls.Button, PresentationFramework" > <property name="Name" value="Next" /> <property name="Width" value="200"/> <property...