1

Closed

Issues with component registration

description

Symptom - spinning up the site results in an error page every time. Elmah logs indicate that
 
"Can't create component 'WhoCanHelpMe.Tasks.NewsTasks' as it has dependencies to be satisfied. WhoCanHelpMe.Tasks.NewsTasks is waiting for the following dependencies: Services: - WhoCanHelpMe.Domain.Contracts.Services.INewsService which was not registered."
 
Cause - components are registered into the container at startup via MEF finding all the exported IComponentRegistrars and calling Register on each. In this case, the ConfigurationRegistrar is being called first and a bug in this registration code is causing incorrect components to be registered. The ConfigurationRegistrar is not filtering the types it finds from the Infrastructure assembly so it registers far more than it needs. As it only knows about the InfrastructureAssembly it resolves types incorrectly e.g. it registers the TwitterNewsService against TwitterNewsService, rather than the INewsService from Domain.
When the service registrar is called, as the TwitterNewsService is already registered, it is not registered again against INewsService, so when the NewsTasks is created, there is no dependency registered for INewsService (even though TwitterNewsService is registered, against TwitterNewsService).
 
So - the order in which MEF calls the registrars seemed to expose this bug, which is why not everyone is seeing it. If the ConfigurationRegistrar is called after then others, then the bug would not present itself as the dependencies are already registered properly.
 
Fix - add a filter into the AllTypes.Pick in the ConfigurationRegistrar to only deal with Configuration types e.g.
 
. If(f => f.Namespace.Contains("Configuration"))
Closed Jan 6, 2010 at 10:45 AM by jamesbroome

comments

wrote Jan 6, 2010 at 10:45 AM

Resolved with changeset 53676.

wrote Feb 14, 2013 at 7:09 PM

wrote May 16, 2013 at 9:26 AM