问题
Does anyone have a good example of a bootstrapper class I can see for reference..
I can't seem to find one anywhere, searched google but no luck.
Searched the helpfile and no luck..
回答1:
If you are searching for a class that that configures the container at the beggining of an application, you can download the latest Prism drop and look for the UnityBootstrapper class.
Take into account that this is only registering the necessary services for a Prism application to run, so your bootstrapper will probably require a different container configuration.
回答2:
You can find another example in the WPF:MVVM & Unity Kiosk sample project. Here the Bootsrapper class:
public class Bootstrapper
{
public Bootstrapper(IUnityContainer container)
{
this.container = container;
}
public Bootstrapper RegisterModule(Type moduleType)
{
IModule module = container.Resolve(moduleType) as IModule;
if (module == null)
throw new ArgumentException("moduleType");
module.Register(container);
return this;
}
private IUnityContainer container;
}
And the IModule interface:
public interface IModule
{
void Register(IUnityContainer container);
}
Finally, One of the implemented Modules:
public class PhotoEditorModule : IModule
{
public void Register(IUnityContainer container)
{
// register default controller
container.RegisterType<IPhotoEditor, Controller>();
// register view models
container.RegisterType<IPhotoEditorViewModel, PhotoEditorViewModel>();
container.RegisterType<IPhotoEditorMenuViewModel, PhotoEditorMenuViewModel>();
}
}
来源:https://stackoverflow.com/questions/4001578/an-example-of-a-bootstrapper-file