I have run into an issue while creating a data service and using Autofac WCF Integration to resolve a dependency on my data model. Registrations are of the form:
builder.RegisterType<MyService>()
.InstancePerDependency();
builder.RegisterType<MyModel>()
.InstancePerLifetimeScope();
where MyModel has a dependency on MyProvider
public MyModel (MyProvider provider)
{
_provider = provider;
}
The problem arises as this provider is registered in Request scope for reasons pertinent to my application.
builder.RegisterType<MyProvider>()
.As<MyProvider>()
.InstancePerMatchingLifetimeScope(RequestContextTag);
As might be obvious, request container is created and disposed on each ASP.Net request.
However, MyModel and MyService are registered in Application scope. I came up with two possible solutions -
- Change scope of provider (not possible as will have to remodel almost the entire app)
- Register service and model in request scope (Don't know if this is possible and if at all, correct)
Any advice/ suggestions appreciated. Thanks.