maartenba / MvcSiteMapProvider

An ASP.NET MVC SiteMapProvider implementation for the ASP.NET MVC framework.
Microsoft Public License
539 stars 218 forks source link

Autofac DI #461

Closed lgoudriaan closed 5 years ago

lgoudriaan commented 7 years ago

Hello,

I'm receiving multiple errors with the message: "There is already an open DataReader associated with this Command which must be closed first." the error happens in a DynamicNodeProvider.

I guess it's a configuration problem, but I can't find the issue.

My boostrapper: builder.RegisterType<UnitOfWork>().As<IUnitOfWork>().InstancePerLifetimeScope(); builder.RegisterType<DbFactory>().As<IDbFactory>().InstancePerLifetimeScope();

repositories and services are registered as InstancePerLifetimeScope()

My node provider:

public class VehicleDynamicNodeProvider : DynamicNodeProviderBase {

private readonly IVehicleService _vehicleService;

public VehicleDynamicNodeProvider(IVehicleService vehicleService)
{
    _vehicleService = vehicleService;
}

public override IEnumerable<DynamicNode> GetDynamicNodeCollection(ISiteMapNode node)
{
    var vehicles = _vehicleService.GetAllSiteMap(); // returns a list of vehicles as noTracking

    if (vehicles != null)
    {
        foreach (var vehicle in vehicles)
        {
            //removed for brevity
            yield return dynamicNode;
        }
    }
}

}

Does someone see the problem?