Good reasons NOT to place ViewModels in separate assembly?

后端 未结 4 1078
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-20 08:35

I\'m developing a project using the MVVM pattern in WPF.

One of the key benefits to MVVM is maintaining clear separation between business logic and presentation.

<
相关标签:
4条回答
  • 2021-02-20 08:55

    The actual question is ... what are assembles for?

    They are a way to separate logic making it unavailable to other code unless you add a reference, so in fact they are a way of hiding parts of code from other parts.

    Given this purpose and the way you are using it I would say that you're doing it right.

    Having said that I find much easier to verify that the Views do not have any code behind in code reviews and keep the views in the same assembly. Less projects = faster compile and load times.

    0 讨论(0)
  • 2021-02-20 09:03

    I don't see any spcific issues with this approach besides the general pro/con for using few/many projects.

    0 讨论(0)
  • 2021-02-20 09:12

    We use this kind of separation in all of our products because it helps us to see if any code violates against the UI - business logic separation.

    Most times we do it the same way as you have suggested:

    • Sample.Presentation.exe (Contains all the WPF stuff, thin assembly)

    • Sample.Applications.dll (Is responsible to the application's workflow, here are all ViewModels)

    • Sample.Domain.dll (Here are the business rules)

    We don't have encountered any issues yet and I don't expect to see any problems in future.

    0 讨论(0)
  • 2021-02-20 09:14

    2 weeks now with my Model & View Models in a dll, my xaml in an exe and no problems whatsoever.

    0 讨论(0)
提交回复
热议问题