Modularity with Prism and Unity in Silverlight

Let me begin by saying that Prism does not strike me as being easy stuff.  Maybe it's not supposed to be, but there's nothing here that seems to make it any easier.  The fact that the instructions begin with hunting down the projects, building it (couldn't I just pull the dlls directly?) and then adding a number of references that I can't say that I fully grok.  Part of the problem is likely that I'm actually exploring the MVVM pattern and the Unity IOC container at the same time, but there's a lot here for what seems like a simple, but very significant gain.  The significant part excites me.  I don't think it's just a testing thing either; the notion of being able to write modules in a complete but separate way and then attach them to my application appeals to me for my current project specifically.  I think it's less about making some kind of custom version for different people (neat idea, but not something that I need) and more about separating the project into parts that are easier to digest.  My prototype, limited as it was, still got way too long and complicated and was difficult to follow by the end.  Breaking things down into smaller files just meant that I had to have all the files open in order to follow it.  By separating things into modules, I am certain that each module is self-contained and so, if I can't understand it, the problem is with that module, not the whole program.  I acknowledge that I may look at this later and decide that I don't really get the advantage the Prism gives me.  That's ok; I'm happy with the value I see in it now and that should let me go further.

So here's the flow as I understand it.  Assuming I have some data object that I want to use, I need a service that returns that object (or a collection of said objects) and an explicitly defined interface for that service.  The interface part seems the most unfamiliar to me, though I don't do a lot of testing/mocking of simple objects like this and I really do see the value in defining things this way (being able to swap out the real service for a mock one so you can test it).

The View Model is where it gets fuzzier for me.  It might be because Silverlight doesn't have a notion of Commands (WPF does) and so I've gotten used to programming without them, which unfortunately means that you're either writing the implementation of a command into the code behind itself or you're creating a hard link between the implementation and the actual UI Event.  What gets me is that the View Model is still pretty View specific; I don't see (yet?) how I could write some kind of generic View that could might work for different View Models.  Maybe that's something I'll get to later.  Still, I get the flow of it.

The magic seems to be in the module class itself.  This provides a concrete link between the data access service interface and the data access service object (this is where I would swap them out for testing).  It also registers a region (an empty space inside the main visual tree) as containing this specific view.  The first seems to be the Unity side of things, while the second is definitely the Prism side.  Even if I were to get sloppy with the IOC side, I think the notion of creating regions and filling them with module Views makes sense.

The shell then needs to have a catalog of modules (I added it with a direct reference, but I can see how you might set up some kind of watcher on a directory and then load the assemblies and add them dynamically).  In this case it's created in the bootstrapper (part of Unity) and the entry point for the application looks like it moves from App.Run() to Bootstrapper.CreateShell() and Bootstrapper.GetModuleCatalog().  I'm still looking into how modules will talk to each other, but I can see how to create a tray full of widgets and how one might swap widgets in and out dynamically.  There's certainly more; I'll keep exploring the framework and expand on this when I figure it out.

I did write code for this, by the way.  I went through Erik Mork's excellent video and made some small tweaks to what he walked through.  I really get a lot of value out of typing things in myself, even if the only changes I were to make were just changing the names of a variable or two.  There's some kind of 'coding muscle memory' that goes along with actually having to create the classes, add the references, add any using statements, and actually write out the code.  I wouldn't say that going through it once means I'll remember it, but it's far better than just reading the code.  The only reason I'm not posting it here is because the description goes a lot further than the actual code does.  A good exercise overall.


Posted by: Raumornie
Posted on: 9/22/2009 at 8:59 PM
Tags: , ,
Categories: Software Kata
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (36) | Post RSSRSS comment feed

Comments

Tyson F. Gautreaux United States

Friday, November 26, 2010 12:54 AM

Tyson F. Gautreaux

Great… This is just what I seem to have been searching for. Precisely how long did it take to make this? Thanks a load for this incredible knowledge.

Luigi Fulk United States

Saturday, November 27, 2010 1:34 PM

Luigi Fulk

I've frequented your port prior to. The additional I learn, the a lot more I keep coming back! ;-P

payday loan United States

Friday, December 10, 2010 8:08 AM

payday loan

I’ve recently started a blog, the info you provide on this website has solved the problem tremendously. Appreciation for your time & work…

payday loan online United States

Friday, December 10, 2010 8:32 AM

payday loan online

Wow, that’s quite a nice read!

payday loans in georgia United States

Monday, December 13, 2010 5:52 PM

payday loans in georgia

Hello from Russia! Will it be practical for me to pages and use a submit within your weblog while using hyperlink to you? I’ve tried emailing you about it problem but it seems i cant reach you, please response when employ a moment, thanks.

pay day loan United States

Monday, December 13, 2010 6:16 PM

pay day loan

Hello, Today in a very new directory of blogs. I don’t understand how your website came up, will need to have been a typo. Your blog looks good, have a nice day.

instant payday loans United States

Tuesday, December 14, 2010 12:17 PM

instant payday loans

My business is really thankful to the author in this post for making this lovely and informative article live in charge of us. We really appreciate ur effort. Continue the great work. . . .

cash loans United States

Tuesday, December 14, 2010 12:39 PM

cash loans

Kudos for posting this type of useful weblog. Your blog isn’t only informative but very artistic too. There are frequently very several those who can write not simple articles that creatively. Keep up the excellent writing !!

Terrilyn Thaker United States

Tuesday, December 14, 2010 9:06 PM

Terrilyn Thaker

I am developing a blog and I am trying to find a new template.Yours looks pretty decent! Feel free to visit my blog and suggest things!

cheap payday advance loans Kyrgyzstan

Wednesday, December 15, 2010 12:39 AM

cheap payday advance loans

excellent read. Subscribed to RSS

payday loans company in Puerto Rico Serbia

Wednesday, December 15, 2010 2:21 AM

payday loans company in Puerto Rico

excellent article. Subscribed to RSS

best online payday loans Libya

Wednesday, December 15, 2010 2:54 AM

best online payday loans

very good article, thank you

short-term installment payday loans in Florida El Salvador

Wednesday, December 15, 2010 4:02 AM

short-term installment payday loans in Florida

Big Thanks for the post... RSS feed added

express payday loans in Louisiana France

Wednesday, December 15, 2010 5:11 AM

express payday loans in Louisiana

very good article, thank you

texas payday loans law Macedonia (FYROM)

Wednesday, December 15, 2010 5:22 AM

texas payday loans law

ery nice post!

online no fax payday loan Hungary

Wednesday, December 15, 2010 12:25 PM

online no fax payday loan

good article, I just gave link to it to a friend, he doing a small amount of research on this point

p90x workout United States

Thursday, December 16, 2010 5:20 AM

p90x workout

P90x equipments are quite helpful to the people and it has been helping the people to remain fit.

actual payday loans no matching services in Alabama Austria

Thursday, December 16, 2010 7:40 AM

actual payday loans no matching services in Alabama

ery nice post;)

500 fast cash loan Lebanon

Thursday, December 16, 2010 11:44 PM

500 fast cash loan

The blog is nice one. I like the design of the blog

instant online payday loans in California Ecuador

Thursday, December 16, 2010 11:55 PM

instant online payday loans in California

very good article, thanks

express payday loans in Tennessee Canada

Friday, December 17, 2010 1:00 AM

express payday loans in Tennessee

excellent read, I merely passed this to a co-worker, he was doing a little amount of research on this point

bad credit personal loans not payday loans in Nevada Republic of the Philippines

Friday, December 17, 2010 3:02 AM

bad credit personal loans not payday loans in Nevada

excellent read, I just gave link to it to a friend, he performing a little amount of research on this point

easy payday loans in Nebraska Sweden

Friday, December 17, 2010 4:13 AM

easy payday loans in Nebraska

This blog is very helpful one. I like the theme of the website

payday loans no checking account required in Florida Taiwan

Friday, December 17, 2010 6:53 AM

payday loans no checking account required in Florida

very good info, thanks

Betting Euro 2012 Voucher United States

Friday, December 17, 2010 10:22 PM

Betting Euro 2012 Voucher

Hi, a splendid blog post man. Thanks However I am experiencing issue with your RSS feed.  Don't know why Fail to subscribe. Does anybody having identical rss feed trouble? Anyone who can assist kindly respond. Thank you.

wow gold United States

Friday, December 17, 2010 10:46 PM

wow gold

Pretty good post. thanks so much for sharing.

wow gold United States

Friday, December 17, 2010 11:29 PM

wow gold

thanks for the useful info. I appreciate it.

dog grooming United States

Saturday, December 18, 2010 10:06 AM

dog grooming

I recently came across your website and have been reading a lot of posts of yours.  I just thought I'd add a quick comment and let you know that you've got a really nice blog.  I'll watch out for updates from you!

get your ex back United States

Saturday, December 18, 2010 1:49 PM

get your ex back

Hello good Angela ,Have been a tea and coffee addict, truly LOVE the fragrance & the tingling sensation of tea as the very first thing after waking up. I Gulp minimum eight cups every 24 hours. Well lovely blog, Have a nice day.

Ladbrokes Casino Worldwide United States

Saturday, December 18, 2010 7:24 PM

Ladbrokes Casino Worldwide

Hey! It's like you understand my mind! You seem to know so much about this, like you wrote the book in it or something. I think that you can do with some pictures to drive the message home a bit, but other than that, this is good blog post. A great read. I will definitely be back.

Bet365 Download United States

Sunday, December 19, 2010 12:40 AM

Bet365 Download

You are not the general blog writer, man.  You certainly have something important to add to the net.  Such a good blog.  I will be back for more.

dui lawyer United States

Sunday, December 19, 2010 2:18 AM

dui lawyer

Hello. impressive job. I did not imagine this. This is a impressive story. Thanks!

e cigarettes United States

Sunday, December 19, 2010 7:49 AM

e cigarettes

The electronic cigarette is amazing! It should of been made years ago. I feel 200 times more healthy since I started using them and stopped my 30 a day habit.

Lamborghini United States

Sunday, December 19, 2010 8:16 AM

Lamborghini

Do you have any other similar blogs and/or related fields of expression.  This information has caused in me some quasi-cascade effect that has resulted in a great rearangement of my knowledge almost akin to a complete paradigm shift in the way I perceive the world.  Thank you so much for this and I bet you wil accumulate a ton of Karma and positive chi due to your wonderful undertaking in this blog!

acai berry supplements United States

Sunday, December 19, 2010 8:49 AM

acai berry supplements

I have lost 30 pounds using acai berry supplement.

Comments are closed