Unity: Problem with resolving RIA DomainContext?

I can't see much wrong here. But having said that, I'm using the Initialize method from the interface in the following way to register types and views for regions.

Up vote 0 down vote favorite share g+ share fb share tw.

I am using PRISM 4 and got my head around almost all features, however as soon as I would like to inject my DomainContext class (RIA) into my view model, the hell breaks loose. :) It would be great if an experienced Unity/Prism developer could give me an advice how to proceed. Within my bootstrapper, I am registering the required class in Unity Container like this: protected override void ConfigureContainer() { base.

ConfigureContainer(); Container.RegisterType(); } Within the NavigationModule, I have the following in the ctor to register the NavigationView with a particular region. Public NavigationModule(IUnityContainer container, IRegionManager regionManager) { _container = container; _regionManager = regionManager; _regionManager. RegisterViewWithRegion(Constants.

NavRegion, () => _container.Resolve()); } The View takes the View Model as dependency: public NavigationView(NavigationViewModel viewModel) { InitializeComponent(); Loaded += (s, e) => { DataContext = viewModel; }; } The ViewModel has the following: public NavigationViewModel(SCMDomainContext context) { _context = context; ConstructCommon(); } As soon as I comment this ctor out and put a en empty ctor, it is all fine, for some reason I can't resolve the SCMDomainContext class. Which is the one you add to have the Domain Context created for you provided by Ria Services. Since I am using Silverlight, I can't see the stack trace to follow the exception, all I get is this message on a page.

What am I missing please? Microsoft JScript runtime error: Unhandled Error in Silverlight Application An exception occurred while initializing module 'NavigationModule'. - The exception message was: Activation error occured while trying to get instance of type NavigationModule, key '' Check the InnerException property of the exception for more information.

If the exception occurred while creating an object in a DI container, you can exception. GetRootException() to help locate the root cause of the problem. At Microsoft.Practices.Prism.Modularity.

ModuleInitializer. HandleModuleInitializationError(ModuleInfo moduleInfo, String assemblyName, Exception exception) at Microsoft.Practices.Prism.Modularity. ModuleInitializer.

Initialize(ModuleInfo moduleInfo) at Microsoft.Practices.Prism.Modularity.ModuleManager. LoadModulesThatAreReadyForLoad() at Microsoft.Practices.Prism.Modularity.ModuleManager. IModuleTypeLoader_LoadModuleCompleted(Object sender, LoadModuleCompletedEventArgs e) at Microsoft.Practices.Prism.Modularity.

XapModuleTypeLoader. RaiseLoadModuleCompleted(LoadModuleCompletedEventArgs e) at Microsoft.Practices.Prism.Modularity. XapModuleTypeLoader.

HandleModuleDownloaded(DownloadCompletedEventArgs e) at Microsoft.Practices.Prism.Modularity. XapModuleTypeLoader. IFileDownloader_DownloadCompleted(Object sender, DownloadCompletedEventArgs e) at Microsoft.Practices.Prism.Modularity.FileDownloader.

WebClient_OpenReadCompleted(Object sender, OpenReadCompletedEventArgs e) at System.Net.WebClient. OnOpenReadCompleted(OpenReadCompletedEventArgs e) at System.Net.WebClient. OpenReadOperationCompleted(Object arg) Your help on this is highly appreciated, Kave silverlight dependency-injection unity prism ria-services link|improve this question asked Feb 5 '11 at 20:02Kave2,05121539 84% accept rate.

I can't see much wrong here. But having said that, I'm using the Initialize method from the interface in the following way to register types and views for regions: #region properties Dependency public IUnityContainer Container { get; set; } Dependency public IRegionManager RegionManager { get; set; } #endregion public virtual void Initialize() { this.Container. RegisterType(new ContainerControlledLifetimeManager()); this.Container.

RegisterType(new ContainerControlledLifetimeManager()); this.RegionManager. RegisterViewWithRegion(Constants. NavRegion, () => this.Container.Resolve()); } Not sure whether it makes a difference if you don't explicitly register the ViewModel and the View type.

Personally I prefer to have control over the way how a type gets resolved by the container.

In fact its best to create a layer for the DomainContext like this. Then its easily resolvable by an IoC: public class ContactModuleService : IContactModuleService { readonly SCMDomainContext _context = new SCMDomainContext(); #region Implementation of IContactModuleService public EntitySet Contacts { get { return _context. Contacts; } } public EntityQuery GetContactsQuery() { return _context.

GetContactsQuery(); } public SubmitOperation SubmitChanges(Action callback, object userState) { return _context. SubmitChanges(callback, userState); } public SubmitOperation SubmitChanges() { return _context.SubmitChanges(); } public LoadOperation Load(EntityQuery query, Action> callback, object userState) where TEntity : Entity { return _context. Load(query, callback, userState); } public LoadOperation Load(EntityQuery query) where TEntity : Entity { return _context.

Load(query); } #endregion }.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions