Hi All,
I have a
asp.net mvc app with entity framework where there should be only 1 DataContext per request.
In the Global.aspx.cs I have following code to register dependencies
var builder = new ContainerBuilder();
builder.RegisterType<DataContext>().InstancePerHttpRequest();
Data.Controller.Instance.Container = builder.Build();
And in the other assembly I have
public abstract class EFRepository<TEntity> : IRepository<TEntity>
{
public EFRepository(DataContext dataContext)
{
}
}
public abstract class Entity
{
//other stuff
protected TRepository GetRepository<TRepository>()
{
return Controller.Instance.Container.Resolve<TRepository>();
}
}
So when ever I want to call GetRepository method I get the following error {"No scope matching the expression 'value(Autofac.Builder.RegistrationBuilder`3+<>c__DisplayClass0[Em.Mdm.Data.DataContext,Autofac.Builder.ConcreteReflectionActivatorData,Autofac.Builder.SingleRegistrationStyle]).lifetimeScopeTag.Equals(scope.Tag)' is visible from the scope in which the instance was requested."} System.Exception {Autofac.Core.DependencyResolutionException}
Please advice as to how this can be avoided. Any changes I need to do are also welcome.
Thank You.