first_page the funky knowledge base
personal notes from way, _way_ back and maybe today

C# StructureMap: Simple Dependency Injection Sample for WPF

In App.OnStartup() have something like this:

ObjectFactory.Initialize(x =>
    x
    .ForRequestedType<ViewModel.IViewModelManager>()
    .CacheBy(InstanceScope.Singleton)
    .TheDefault.Is.OfConcreteType<ViewModel.ViewModelManager>()
);

Use the requested type like this:

var manager = ObjectFactory.GetInstance<IViewModelManager>();
manager.Register(this);

This pattern is most quick and most dirty.

mod date: 2010-03-26T16:35:58.000Z