NBear Presenter需要多个Service时的处理方法

来源:互联网 发布:非洲有没有帅哥知乎 编辑:程序博客网 时间:2024/04/29 16:59

当需要多个service的时候可以有两种方法:

第一种是在范型参数中定义两个以上service,注意此时你的Presentor要实现IPresentor2接口,是IPresentor2不是IPres­entor。

地而种更通用和推荐的方法是,使用让Presentor继承不带IModel的Presentor<IView>(注意该方法也要实现IPresentor2接­口),
在Presentor中可以直接使用NBear.IoC.Service.ServiceFactory.Create
().GetService<IServiceType>()取得任意数量service(Create().返回的是一个ServiceFactory的Si­ngleton)。这样service的数量没有限制,而且view和presentor对具体的service也没有任何依赖,因此这种方法就更通用。

Teddy

On 2/7/07, homer <home...@gmail.com> wrote:

> 以下是IPresenter接口的定义:
>    // Summary:
>    //     Interface of all presenters
>    public interface IPresenter
>    {
>        // Summary:
>        //     Gets the type of model.
>        Type TypeOfModel { get; }
>        //
>        // Summary:
>        //     Gets the type of view.
>        Type TypeOfView { get; }

>        // Summary:
>        //     Binds the model.
>        //
>        // Parameters:
>        //   model:
>        //     The model.
>        void BindModel(object model);
>        //
>        // Summary:
>        //     Binds the view.
>        //
>        // Parameters:
>        //   view:
>        //     The view.
>        void BindView(object view);
>    }
> 但是当我使用Presenter<IDefaultView, INoticeService, ICollegeService,
> ICourseService, IApplyService, IUserService>作为基类继承时,编译器提示没有完全实现
> IPresenter接口。查看Presenter,发现其定义如下:
> // Summary:
>    //     Base class of all presenters
>    //
>    // Type parameters:
>    //   ViewType:
>    //
>    //   IModelType1:
>    //
>    //   IModelType2:
>    //
>    //   IModelType3:
>    //
>    //   IModelType4:
>    //
>    //   IModelType5:
>    public abstract class Presenter<ViewType, IModelType1,
> IModelType2, IModelType3, IModelType4, IModelType5> : IPresenter2
>        where IModelType1 : NBear.IoC.Service.IServiceInterface
>        where IModelType2 : NBear.IoC.Service.IServiceInterface
>        where IModelType3 : NBear.IoC.Service.IServiceInterface
>        where IModelType4 : NBear.IoC.Service.IServiceInterface
>        where IModelType5 : NBear.IoC.Service.IServiceInterface
>    {
>        // Summary:
>        //     The model 1
>        protected IModelType1 model1;
>        //
>        // Summary:
>        //     The model 2
>        protected IModelType2 model2;
>        //
>        // Summary:
>        //     The model 3
>        protected IModelType3 model3;
>        //
>        // Summary:
>        //     The model 4
>        protected IModelType4 model4;
>        //
>        // Summary:
>        //     The model 5
>        protected IModelType5 model5;
>        //
>        // Summary:
>        //     The view
>        protected ViewType view;

>        protected Presenter();

>        // Summary:
>        //     Gets a value indicating whether this
> NBear.MVP.Presenter
> <ViewType,IModelType1,IModelType2,IModelType3,IModelType4,IModelType5>
>        //     is initialized.
>        public bool Initialized { get; }
>        //
>        // Summary:
>        //     Gets the types of the model.
>        public Type[] TypeOfModels { get; }
>        //
>        // Summary:
>        //     Gets the type of the view.
>        public Type TypeOfView { get; }

>        // Summary:
>        //     Binds the models.
>        //
>        // Parameters:
>        //   model:
>        //     The models.
>        public void BindModels(object[] models);
>        //
>        // Summary:
>        //     Binds the view.
>        //
>        // Parameters:
>        //   view:
>        //     The view.
>        public void BindView(object view);
>    }
> 在Presenter中实现了TypeOfModels和BindModels,却没有实现IPresenter接口中定义的TypeOfModel和
> BindModel。

> 对于这个问题,不知道是否属于设计疏漏,还是有其他的使用方法我不知道?
> 另外对于Presenter的设计,感觉需要改进,现在对于多Service的支持有些丑陋,也没有很好的扩展性。假设需要支持8个或以上的
> Service,这种设计就不支持了。总不至于我们再写一个支持8个Service的范型吧?

> 现在的项目正在使用NBear,感觉很多功能很方便,也改变了我以前的设计习惯(以前是table->modle,现在是model->table),
> 感觉更OO了。但是NBear还不成熟,特别是文档稀缺,SDK文档给予的信息相当少(基本上只能查到类和函数的定义,不能看出使用方法和注意事项)。
> 所有能够参考的只能是teddy写的教程,稍高级的用法只能看源码分析,学习和使用都不方便,需要改进。

> 总的来说,谢谢teddy和其他NBear开发者,谢谢你们带给我们这么好的工具。

 

转自:http://groups.google.com/group/nbeargroup/msg/86875e4511bcf831

原创粉丝点击