There is an unsaved comment in progress. You will lose your changes if you continue. Are you sure you want to reopen the work item?
Issues with component registration
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,
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"))