An example of a bootstrapper file?

2019-07-21 14:51发布

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..

2条回答
狗以群分
2楼-- · 2019-07-21 15:12

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.

查看更多
叼着烟拽天下
3楼-- · 2019-07-21 15:14

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>();
    }
}
查看更多
登录 后发表回答