I have started using Ninject a dependency injection framework for .NET. I find it very easy to use and recommend that people take a look.
Something in particular that I found useful is the ability to bind open generic types.
class Program{ static void Main(string[] args) { var k = new StandardKernel(new MyModule());
var di = k.Get<Data<int>>(); di.Content = 14; Console.WriteLine(di.Content);
var ds = k.Get<Data<string>>(); ds.Content = "hello"; Console.WriteLine(ds.Content); }}
class MyModule : StandardModule{ public override void Load() { Bind(typeof(IData<>)).To(typeof(Data<>)); }}
class Data<T> : IData<T>{ public T Content { get; set; }}
interface IData<T>{ T Content { get; set; }}
Very cool!
Remember Me
© Copyright 2008 Andrew Davey Theme Design by Bryan Bell newtelligence dasBlog 1.9.6264.0 | Page rendered at Monday, July 21, 2008 12:55:56 AM (GMT Standard Time, UTC+00:00) Pick a theme: BlogXP calmBlue Candid Blue dasBlog Discreet Blog Blue Elegante essence Just Html MadsSimple Mobile Mono Movable Radio Blue Movable Radio Heat nautica022 orangeCream