2011-03-10 9 views
2

私はEntity Framework 4.0を使用して、asp.netから以下のコードを呼び出しています。私はいくつかのデータを挿入する必要があるアドレステーブルを持っています。私のコードはStructureMap例外コード:202 PluginFamilyにデフォルトインスタンスが定義されていません

 IRepository<Address> addressRepository; 
     int addressHOCODE = 0; 

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

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

です。addressRepository = ObjectFactory.GetInstance<IRepository<Address>>();行では、次のエラーが発生しています。

のStructureMap例外コード:202ニュートラル PluginFamily Domain.IRepository`1 [[Data.Address、 DataAccessLayerNew、バージョン= 1.0.0.0、文化= 、が定義されていません 既定のインスタンス なPublicKeyToken = nullを] ]、 DataAccessLayerNew、バージョン= 1.0.0.0、 ニュートラル文化=、なPublicKeyToken = nullを

+0

Global.asaxにいくつかのエントリがありません。これがまさにその理由だ。 – Zohaib

答えて

5

あなた自身のためにこれを働いたが、このページに遭遇するかもしれない他の人を助けることのように、私が期待ルックスsomethiを参照してくださいGlobal.asax.csファイルに次のように入力してください。

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>(); 
      }); 
     } 
    } 
} 
+0

助けてくれてありがとう。 – Zohaib

関連する問題