简体   繁体   English

具有业务层和DAL的WPF体系结构

[英]WPF Architecture with Business Layer and DAL

Im starting a new application in WPF and I want it to have a good architecture so that it can be maintainable. 我在WPF中启动了一个新应用程序,我希望它具有良好的体系结构,以便可以维护。 Im using Entity Framework and what I planned so far is. 我正在使用实体框架,到目前为止我计划的是。

• View Layer: One project (startup) with the startup view, and main menus. •视图层:一个具有启动视图和主菜单的项目(启动)。 Different projects for each type of view, for example, if I have views related with Books then I'd have a project named BooksView with all the views. 每种视图类型的项目都不同,例如,如果我有与Books相关的视图,那么我将有一个名为BooksView的项目,其中包含所有视图。

• Business Layer: One project for each type of Business Class, for example BusinessBooks. •业务层:每种业务类别(例如,BusinessBooks)的一个项目。 Each one would have a Repository with the specific operations and any helpers to do calculations if needed. 每个人都将拥有一个包含特定操作的存储库,并在需要时由任何助手进行计算。

• Data Acess Layer: It contains a folder named Entity Framework with the DBContext and with the T4 generated classes and with a class named ContextCreator which has the following code: •数据访问层:它包含一个名为Entity Framework的文件夹,该文件夹具有DBContext和T4生成的类以及名为ContextCreator的类,该类具有以下代码:

public class ContextCreator : IDisposable
{
    private MesaOperativaDB context;

    public ContextCreator()
    {
        context = new MesaOperativaDB();
    }

    public MesaOperativaDB getContext()
    {
        return context;
    }

    public void Dispose()
    {
        context.Dispose();
    }
}

Then a view would use the static repository of any project of the Business Layer that needs, and this repository would use the class above to get the DBContext and use it like this: 然后,视图将使用需要的业务层任何项目的静态存储库,并且该存储库将使用上面的类来获取DBContext并像这样使用它:

    public static List<Novedades> GetNovedades()
    {
        using (ContextCreator db = new ContextCreator())
        {
            IQueryable<Novedades> novedades = db.getContext().Set<Novedades>().AsQueryable();
            return novedades.ToList();
        }
    }

Is this approach any good? 这种方法好吗? Thank you in advance guys. 预先谢谢你们。

Though I am quite not sure of your application scale but it seems good to me that you have started on a right path for separation of concerns. 虽然我不确定您的应用程序规模如何,但是对我来说,您似乎已经开始了分离关注点的正确道路。

But you may need to rethink if creating separate project for each category of views does not introduce unnecessary complexity. 但是,如果为每种视图类别创建单独的项目不会引入不必要的复杂性,则可能需要重新考虑。

Again I am not sure if you are new to WPF, but for the View layer for better maintainability, loose coupling and hence testability etc., MVVM is the best chosen pattern to organize things in place. 再次,我不确定您是否是WPF的新手,但是对于View层来说,它具有更好的可维护性,松散的耦合以及因此的可测试性等,因此MVVM是组织适当内容的最佳选择。 For getting MVVM in place you may handcode everything from scratch or there are nice frameworks available like: 为了安装MVVM,您可以从头开始手动编码所有内容,也可以使用不错的框架,例如:

MVVM Lite MVVM Lite

Assisticant 协理的

Also if you are planning towards a relatively big(layman term!!)/enterprise class application and since you are looking for highly maintainable, flexible application you may consider using PRISM framework from Microsoft . 另外,如果您打算开发一个相对较大的(企业术语!)/企业类应用程序,并且由于您正在寻找高度可维护,灵活的应用程序,则可以考虑使用Microsoft的PRISM框架 Prism Guidance and downloadable PDFs etc. 棱镜指南和可下载的PDF等

Once you finalized on the View part, the you need to focus on Validations for your app and whether you would be implementing validations in the ViewModel or in your domain objects. 在“视图”部分上完成后,您需要关注应用程序的验证以及是否要在ViewModel或域对象中实现验证。 Assisticant framework has some good domain-centric validation mechanism built into it. 辅助框架内置了一些良好的以域为中心的验证机制。

For the Data access layer, since you chose to go with EF, from my understanding so far, the Unit-Of-Work with Repository pattern would greatly help you to gain extensibility, testability etc. features. 对于数据访问层,由于您选择使用EF,根据我的理解,到目前为止, 带存储单元的工作单元模式将极大地帮助您获得可扩展性,可测试性等功能。

If you are planning high on unit testability and loose coupling of your application, you need to consider Inversion of Control and Dependency Injection perhaps with a suitable framework. 如果您计划在单元可测试性和应用程序的松散耦合方面进行高规划,则需要考虑使用合适的框架来进行控制反转和依赖注入。

Here you can check a WPF application framework to understand on how to organize different areas of a WPF application in a layered approach. 在这里,您可以检查WPF应用程序框架,以了解如何以分层方式组织WPF应用程序的不同区域。

Hope this may help you to dig further. 希望这可以帮助您进一步挖掘。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM