StructureMap working locally, but not on production server

562 views Asked by At

I developing a MVC5 application, where I am using StructureMap as my DI framework. The application works fine, when I run it locally from Visual Studio. However when I publish to our production server, I get the "No parameterless constructor..." error. I've Googled a solution and found a suggestion to add the code below to an empty constructor in the controller, in order to get a more detailed exception:

public class HomeController : Controller
{
    public HomeController()
    {
        _bll = StructureMap.ObjectFactory.GetInstance<IAgentStatsBll>();
    }

    private IAgentStatsBll _bll;

    public HomeController(IAgentStatsBll bll)
    {
        _bll = bll;
    }

    public ActionResult Index()
    {
        HomeViewModel model = new HomeViewModel {Authors = _bll.GetAuthorsWithCommentsOnDate(DateTime.Now.AddDays(-60))};
        return View(model);
    }
}

When I run this code on the production server, I get an error saying:

No default Instance is registered and cannot be automatically determined for type 'ZendeskAgentStats.BLL.IAgentStatsBll'. 
There is no configuration specified for ZendeskAgentStats.BLL.IAgentStatsBll

If I understand the error correct, it says that SM cannot figure out which concrete type it should use for the IAgentStatsBll interface. However this is configured in the DefaultRegistry.cs: public class DefaultRegistry : Registry { #region Constructors and Destructors

    public DefaultRegistry()
    {
        Scan(
            scan =>
            {
                scan.TheCallingAssembly();
                scan.AssemblyContainingType<IAgentStatsBll>();
                scan.AssemblyContainingType<IAgentStatsDal>();
                scan.AssemblyContainingType<IAgentStatsContext>();
                scan.AssemblyContainingType<ZendeskAPIMethods>();
                scan.WithDefaultConventions();
                scan.With(new ControllerConvention());
            });
        For(typeof(IGenericRepository<>)).Use(typeof(GenericRepository<>));
    }

    #endregion
}

Can anyone figure out why it is working locally but not on the server?

0

There are 0 answers