views:

535

answers:

2

I am a total newbie on Prism. I have been getting to understand a lot from questions on SO and from various Blogs. I am using latest build – V2

I want some explanations on things that may be pretty easy things for you guys but it’s just not getting into my brains (small one for that). Instead of doing it all right the first time , for which I have spent more than two weeks looking at various blogs, webcast …., I thought to start a project and learn. The amount of information on those hundreds of sites was overwhelming and difficult to digest. Currently my project is setup like this Shell --  Menu Module- ViewModel - - -> Menu Service -- -- > Menu Repository --- Data

All are in different assembly

MyShell --- MenuModule ---MyServices -- Myrepository

Shell is required to reference modules ( thought I am sure I can add it using string) later on .

ViewModel has a reference to View - Can live with it for now

View Model requires to use menu service and menu service uses repository

All are built with constructor injection. I have it working now by having module reference MyService and Myrepository projects and then registering types at module level. But this does not feel good. I don’t want to hard reference any projects. If we are referencing projects why use IoC. In MenuModule.cs ( which is in the root of module) I can register views with unity container I think I am getting a feel that the answer to this one may lie in the first question

  1. Is Configuration file the answer/ Should I use configuration file for true decoupling?
  2. If (somehow) we can register types from code, should we register types at module level ( I don’t want to have hard reference to projects)
  3. I need to know the Interfaces in advance so do you recommend separate assembly for just Interfaces?

Bear with me if the questions sound real stupid 

A: 

You're definitely on the right track. Use the configuration file to register your types, and put the interfaces in a separate assembly.

Thank you Jeff. Have a look at my comment on registering type with qualified assembly names
TheMar
+1  A: 

You don't need a configuration file for true decoupling. All you need is to register your types in your shell's bootstrapper. I usually break up my projects and refs like this.

Contract Assembly (Contains only a few simple types and interfaces)

Referenced by:

  • Shell
  • Modules

Shell (Contains concrete implementations of interfaces defined in Contract assembly)

Referenced by:

  • No one

Modules (Declares dependencies on interfaces defined in Contracts assembly, for instance IMenuRegistry)

Referenced by:

  • No one (I use a Directory Module to search for modules in a directory)

Here's a sample project I put together. In this sample I reference the module from the shell for simplicity's sake, but you can remove that reference and use a directory module catalog to load the compiled module at runtime: http://dl.getdropbox.com/u/376992/CAGMenus.zip

Hope this helps, Anderson

Anderson Imes
@Anderson:Thanks for your reply.Another clarification required.. If Shell has all concrete implementations of Interfaces then all my classes will be instntiated when my application starts or is it that IoC will resolve the types only when requested (on demand)
TheMar
@Anderson- Thanks for the sample
TheMar
They are instantiated on demand unless you specify a special lIfetime manager.
Anderson Imes
Is there a way I can say _container.RegisterType(IMenuRepository,<Myassembly, myclass, VersionNo>)
TheMar
You can. You'd have to do a Type.GetType and pass a string. However I think I know what you are getting at and I think it would be better for you if your MenuModule registered its implementation of IMenuRegistry in a normal way in Initialize and your other modules simply declared that they had a module dependency on "MenuModule".
Anderson Imes
More about the [ModuleDependency("MenuModule")] stuff is here: http://msdn.microsoft.com/en-us/library/dd458911.aspx
Anderson Imes
@Anderson. Thanks A lot of things have got cleared from your comments
TheMar

related questions