开发者

An example of a bootstrapper file?

开发者 https://www.devze.com 2023-01-21 05:25 出处:网络
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.

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


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.


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>();
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号