I've got an MVC app built on EF4.3 and am trying to do some refactoring/cleanup by injecting the DbContext into entities instead of passing it around. I already am using Autofac to pass the context to my controllers and that works great. But using AutowireProperties to set the DbContext property on the entities isn't working (never seems to set the property). Here's my setup:
var builder = new ContainerBuilder();
builder.RegisterControllers( typeof( MvcApplication ).Assembly );
builder.RegisterType<Database.Context>().InstancePerHttpRequest().WithParameter( "viewmodel_mapper", new Models.ViewModelMapper() );
builder.RegisterType<Database.Appointment>().PropertiesAutowired();
builder.RegisterType<DocStore.Context>().InstancePerHttpRequest();
var container = builder.Build();
DependencyResolver.SetResolver( new AutofacDependencyResolver( container ) );
The Database.Appointment has a public property, e.g.:
public Context Context { get; set; }
The short answer is I want to continue to set the context per http request on the controller, then set that same context to an EF entities that have the DbContext property.