Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVVM, Unity, Prism, MEF, Caliburn - What should I use?

Please help - I'm getting lost!

I'm writing a small desktop application which has some controls and some screen. This should later be integrated with a small web site, also having some screens. The idea is to let the user edit videos and select images, and then share their results with her friends.

The desktop app is using C# WPF, the web site - ASP.Net MVC.

I read that growing the application past a few screens would be easier using MVVM. So I started searching and discovered Caliburn.Micro and MVVM.Light. I have downloaded some tutorials but, just as I was getting ready to deep-dive into the material, I found here on S.O. that there's also Prism, MEF, Unity, ReactiveUI - This is becoming too much!

I'm terrible at learning new things - It's taking me ages to study WPF and ASP.Net MVC. I don't want to study lots of new material only to find out later that it's not relevant. And I don't have an architect to instruct me.

So my question is: Could you put these frameworks and technologies in perspective, and suggest which I should focus on studying and using (esp. what can be later used with Windows 8)?

like image 483
Avi Avatar asked May 29 '12 12:05

Avi


3 Answers

If you want to build an MVVM application (which you probably do for various advantages), then you want an MVVM framework.

I would recommend Caliburn.Micro, as it is straightforward to implement following the examples on the Caliburn.Micro documentation page. It also has a very compelling convention over configuration mechanism, and uses an Actions system to invoking verbs (methods) on your view models from the view. This is more powerful than any other mechanism I've seen.

Prism is quite a heavyweight framework which includes elements of MVVM design to help the implementation, as well as being particularly tailored towards building composite applications (applications that are built up of decoupled components within a hosting shell).

MEF is useful for these types of applications that need to discover plugins or extensions to the application (even after the application has bootstrapped), and can be used alongside an MVVM framework such as Caliburn.Micro. MEF can also be used for implementing inversion of control, but doesn't provide some of the core features found in other inversion of control containers, so you may decide to only use it to implement plugin functionality.

Unity is an IoC container, and would be used to implement dependency injection for your general application infrastructure. There are lots of IoC containers in the .NET space though, some of which offer either improved performance, additional features, or a more friendly API.

I don't know about ReactiveUI as I haven't used it.

If you're talking about maximising code reuse for a move to WinRT, then MVVM is a great choice.

like image 131
devdigital Avatar answered Nov 09 '22 22:11

devdigital


PRISM already include MEF and MVVM logic :)

Ok little bit of explanation here:

MVVM stand for logic in your application. Actually clever way of decoupling of View, View-Model and Model. Don't know any best (?) framework to do it - you could check Catel if you want or MVVM Light but it just a tons of code from someone who understand the MVVM logic and just make it easy to implement it. You could actually try to write your own MVVM framework and see that 'there's no secret ingredient' - just the same repeating code and same classes, etc... Actually you don't need any MVVM framework to implement MVVM.

Once you learn and write MVVM you immediately run into question - How I NUnit test it in decoupling way (this is not trivial problem in Silverlight for example) - so here all IOC/Inject framework come into play. For example MEF. Consider following example to understand a big picture about Inject framework:

Project 'Shared', written in 'least delimiter' (for example Portable Library)

    public interface IAmSharedInterface
    {
        string SayHello();
    }

Project 'Main', reference only 'Shared' project

    public class IAmMainClass
    {
        [ImportingConstructor]
        public IAmMainClass(IAmSharedInterface SharedInterface)
        {
             SharedInterface.SayHello();
         }
    }

Project 'Implementor', reference only 'Shared' project

   [Export(IAmSharedInterface)]
   public class IAmImplementor: IAmSharedInterface
   {
       public string SayHello()
       {
          return "Hello from implementator class to whoever using it";
       }
    }

You see - there's no direct reference between 'Main' and 'Implementator' projects - all 'magic' happens in MEF/Unity build/resolve process. So you could easily run NUnit test on Main without using 'Implementor' project and 'Implementor' with 'Main'. There's also a scenario where other project could implement and export 'IAmSharedInterface' specially for testing purposes.

So back to PRISM - it have all (!) this. I know it's not easy framework to understand right away and it doesn't suitable for simple 'Hello World' programs but once you learn it - there's no way back. It just glue all the parts together and give you big degree of freedom in using whatever moq framework you want (for example Rhino).

Prism developing in Microsoft so (I hope) it will be supported not just in Windows 8 but in Windows 9 and in all future versions.

Whatever you asked it's all inside: MVVM, Inject, decouple/plug-ins, easy to read and test

like image 27
Alex F Avatar answered Nov 09 '22 21:11

Alex F


To save adding to the detailed information above, I'll attempt to make life easy for you.

1) For now, forget about IOC / Dependency Injection / Plugin architecture. You say you're creating a simple app, so forget about this for now. Keep your code tidy and you can implement this later if necessary (it's good stuff).

2) Out of the frameworks you've listed I would suggest Caliburn.Micro. It's relatively straight-forward and lightweight. It wouldn't take you long to get up and running.

3) Create your model in a separate assembly which you can use for both your windows app and your MVC website.

Keep it simple and don't get bogged down with all the technologies.

like image 14
pfeds Avatar answered Nov 09 '22 22:11

pfeds