StructureMap Exception Code: 202 No Default Instance defined for PluginFamily

风流意气都作罢 提交于 2019-12-11 07:00:25

问题


I am Using Entity Framework 4.0 calling the below mentioned code from asp.net. I have a address table in which I need to insert some data. my code is :

        IRepository<Address> addressRepository;
        int addressHOCODE = 0;

        try
        {
            **addressRepository = ObjectFactory.GetInstance<IRepository<Address>>();**

            addressRepository.Add(address);
            addressRepository.SaveChanges();
            addressHOCODE = address.HOCODE;
        }
        catch ...

At the addressRepository = ObjectFactory.GetInstance<IRepository<Address>>(); line, we're getting the following error.

StructureMap Exception Code: 202 No Default Instance defined for PluginFamily Domain.IRepository`1[[Data.Address, DataAccessLayerNew, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], DataAccessLayerNew, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null


回答1:


Looks like you worked this out for yourself, but to help others who might come across this page, I'd expect to see something like this in the Global.asax.cs file:

using System;

namespace Host
{
    public class Global : System.Web.HttpApplication
    {
        protected void Application_Start (object sender, EventArgs e) {
            ObjectFactory.Configure(config => 
            {
                config.For<IRepository>().Use<ConcreteRepository>();
            });
        }
    }
}


来源:https://stackoverflow.com/questions/5255778/structuremap-exception-code-202-no-default-instance-defined-for-pluginfamily

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!