An example of a bootstrapper file?

为君一笑 提交于 2020-01-04 05:17:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!