none
Mef versus unity(authentication-child window)

    Question

  • http://akashkava.com/blog/391/mef-vs-unity-in-composite-application-prism/

    I was trying to come up with a simple application for a child window(authentication) either unity or mef in prism for a container

    when I came accross this article  and pleas correct me if I am wrong. Lets say you wanted to have region management and a catalog in prism either using mef or prism

    My understanding is that in your basic catalog. you would have different modules etc

    Lets call this Catalog(My catalog) 

    In mef you must use this way 1 Module A  (Authentication-child window)  

                                                     Module B 

                                                    Module  C

    In Mef this acts a singleton which means you only call module a  once and that's it

    In unity(prism)  according to the above article you change this per instance and you should be able to share accross multiple

    applications?

    (continued)      

      

     

    Friday, June 10, 2011 3:47 PM

Answers

  • Billsm,

    I am not sure that I understand you and most of those links refer to Jeremy's blogs.

    Main bootstrapper

    public class MyBootstrapper : UnityBootstrapper
        {

            protected override DependencyObject CreateShell()
            {
                return ServiceLocator.Current.GetInstance<MainPage>();
            }

            protected override void InitializeShell()
            {
                base.InitializeShell();

                Application.Current.RootVisual = (UIElement)this.Shell;
            }
        }

     

     public partial class App : Application
        {

            public App()
            {
                this.Startup += this.Application_Startup;
                this.Exit += this.Application_Exit;
                this.UnhandledException += this.Application_UnhandledException;

                InitializeComponent();
            }

            private void Application_Startup(object sender, StartupEventArgs e)
            {
                MyBootstrapper b = new MyBootstrapper();
                b.Run();
            }

    ChildBootstrapper.

    public class ChildBootstrapper : UnityBootstrapper
        {
            protected override DependencyObject CreateShell()
            {
                return ServiceLocator.Current.GetInstance<ChildWindow1>();
            }

            protected override void InitializeShell()
            {
                base.InitializeShell();

                ChildWindow1 f = (ChildWindow1)this.Shell;
                f.Show();
            }
        }

     

    public partial class MainPage : UserControl
        {
            public MainPage()
            {
                InitializeComponent();
            }

            private void button1_Click(object sender, RoutedEventArgs e)
            {
                ChildBootstrapper c = new ChildBootstrapper();
                c.Run();
            }
        }

    Tuesday, June 14, 2011 3:43 AM

All replies

  • Lets pretend let's say I wanted to use Module A(child window-call authentication)  on every module

    1 module A called before Module B

    Module A before Module C

    Module A before Module D etc

    In mef this does not look possible. Is this possible for UNITY(region) navigation

    using either dependenency  or  attached  os something else??

    Friday, June 10, 2011 4:07 PM
  • It's absolutely possible in MEF - it's a core feature. MEF is by default singleton, but you can easily over the policy creation on either the export or the import side and use non-shared modules if you prefer (although more often than not there is not a reason to go non-shared).

    I'm not sure you're example is clear. Sounds like before going to the module you want to check some claim for access? That is bread and butter LOB type scenario and totally possible, but your question is too generic to talk specifics.

    That page by the way was not a good comparison of MEF and Unity. The author obviously did not have much knowledge of MEF and stated a lot of things that simply aren't true about it. I commented there and he replied so I'll leave it that.

    Friday, June 10, 2011 4:35 PM
  • Thanks Jeremy, I have read alot of your examples I have not seen alot of good examples on using mef using child windows...

    alex van beek showed this example http://blogs.infosupport.com/blogs/alexb/archive/2011/02/21/silverlight-4-creating-useful-base-classes-for-your-views-and-viewmodels-with-prism.aspx

    I know alot of people like Prism Mef over prism(unity) I find myself attracted to  Prism(unity) than prism Mef

    Is their anything that I can read up on this subject that would be able to help?

    PLease keep this either to prism(unity) or Prism (mef) I also find myself attracted to using regions etc for navigation

    (like master pages) ?? Thanks for your help....    

    Friday, June 10, 2011 5:05 PM
  • I guess I refuse to let this topic die because I feel it is not yet resolved

    http://blogs.u2u.be/diederik/post/2011/01/15/Using-the-Prism-40-Event-Aggregator.aspx

    This is one point of a example using the mediator pattern in prism, mvvm mef etc

    Saturday, June 11, 2011 3:12 PM
  • I'm still not sure what there is to resolve. I don't use Prism personally so I can't answer to it specifically - I use MEF as it provides all I've needed, with a few small things such as event aggregation and region management that are easy enough to layer on top of it. Prism is a great framework, especially when you know what and how to use pieces of it.

    What is not yet resolved for you?

    Saturday, June 11, 2011 3:22 PM
  • Jeremy, Thanks again, I guess what I am confused (I would like to use event aggregator) with prism

    1 I would like to use this with a child window (authentication)

    however  this is my problem

    Do I use this Prism(Mef)??

    or just plain Prism(unity)??

    What is your opinion on this matter? Thanks   

    Saturday, June 11, 2011 9:48 PM
  • Hi Billsm,

    Create second Boostrapper then you can use core service but the main problem is that main region will be losted you should obtain it first.

    Sunday, June 12, 2011 8:31 AM
  • Thaicarrot,  I am not sure if I understand...could you explain in more detail??

    Maybe I mad this more complicated for myself

    I guess one of the things I would like to do is to create a child window...My understanding is that you can use a child window

    in a dialog http://www.wintellect.com/CS/blogs/jlikness/archive/tags/prism/codeproject/default.aspx

    http://www.codeproject.com/Articles/42728/Decoupled-ChildWindow-Dialogs-with-Prism-in-Silver.aspx

    http://blogs.southworks.net/ibaumann/2008/09/26/windowregionadapter-for-compositewpf-prism/

    Sunday, June 12, 2011 3:29 PM
  • Jeremy.

    Thanks for your help still trying to decide if I want to mef prism

    or mef unity....I want to keep it simple... 

    Sunday, June 12, 2011 5:05 PM
  • Billsm,

    I am not sure that I understand you and most of those links refer to Jeremy's blogs.

    Main bootstrapper

    public class MyBootstrapper : UnityBootstrapper
        {

            protected override DependencyObject CreateShell()
            {
                return ServiceLocator.Current.GetInstance<MainPage>();
            }

            protected override void InitializeShell()
            {
                base.InitializeShell();

                Application.Current.RootVisual = (UIElement)this.Shell;
            }
        }

     

     public partial class App : Application
        {

            public App()
            {
                this.Startup += this.Application_Startup;
                this.Exit += this.Application_Exit;
                this.UnhandledException += this.Application_UnhandledException;

                InitializeComponent();
            }

            private void Application_Startup(object sender, StartupEventArgs e)
            {
                MyBootstrapper b = new MyBootstrapper();
                b.Run();
            }

    ChildBootstrapper.

    public class ChildBootstrapper : UnityBootstrapper
        {
            protected override DependencyObject CreateShell()
            {
                return ServiceLocator.Current.GetInstance<ChildWindow1>();
            }

            protected override void InitializeShell()
            {
                base.InitializeShell();

                ChildWindow1 f = (ChildWindow1)this.Shell;
                f.Show();
            }
        }

     

    public partial class MainPage : UserControl
        {
            public MainPage()
            {
                InitializeComponent();
            }

            private void button1_Click(object sender, RoutedEventArgs e)
            {
                ChildBootstrapper c = new ChildBootstrapper();
                c.Run();
            }
        }

    Tuesday, June 14, 2011 3:43 AM
  • Thanks, those links are just to help me out. They are just a guide for myself, I guess, like i said I am still learning...    

    I will mark this post as answered....

    Tuesday, June 14, 2011 8:15 AM
  • Hi,

    You can also use IUnityContainer's "CreateChildContainer" create child windows then register core service manaully.

    Tuesday, June 14, 2011 8:39 AM