0

SharePoint 2010 Web アプリケーションで NHibernate を構成しています。以前は、マッピングとドメインが 1 つのプロジェクトにある場合に正常に機能していました。しかし、リファクタリング プロセス中に、ソリューションをいくつかのプロジェクトに分割しました。また、nhibernate 構成を初期化するカスタム IHttpModule も実装しました。

    protected void context_BeginRequest(object sender, EventArgs e)
    {
        var httpApplication = sender as HttpApplication;

        lock (httpApplication )
        {
            if (!httpApplication.Context.Items.Contains(ApplicationConstants.IsApplicationInitialized))
            {
                httpApplication.Context.Items.Add(ApplicationConstants.IsApplicationInitialized, true);
                InitInRequest(httpApplication);
            }
        }

        httpApplication.Context.Items.Add(ApplicationConstants.SESSION, NhibernateManager.GetSession());
    }

    private void InitInRequest(HttpApplication httpApplication)
    {
        NhibernateManager.Init(ApplicationVariables.ApplicationSettingsPath);
    }

そしてNHibernateManager.Init():

    public static void Init(string configurationFilePath)
    {
        specifiedConfigurationFilePath = configurationFilePath;
        Configure();
        InitSessionFactory();
    }

    private static void Configure()
    {
        if (config == null)
        {
            if (string.IsNullOrEmpty(specifiedConfigurationFilePath) == false)
            {
                config = new Configuration();
                config = config.Configure(specifiedConfigurationFilePath);
                config = Fluently.Configure(config)
                                    .Mappings(m => m.FluentMappings.AddFromAssemblyOf<ItemMap>())
                                    .BuildConfiguration();
            }
            else
            {
                config = Fluently.Configure()
                                    .Mappings(m => m.FluentMappings.AddFromAssemblyOf<ItemMap>())
                                    .BuildConfiguration();
            }
        }
    }

BuildConfiguration() には非常に奇妙なエラー (InnerException) があります:「エントリ ポイントが見つかりませんでした。」スタック トレースは、マッピング情報の取得がエラーの原因であることを示しています。

at System.Collections.Generic.IDictionary`2.TryGetValue(TKey key, TValue& value)
at NHibernate.Cfg.Configuration.GetClassMapping(String entityName)
at NHibernate.Cfg.Configuration.GetClassMapping(Type persistentClass)
at FluentNHibernate.PersistenceModel.Configure(Configuration cfg)
at FluentNHibernate.Cfg.MappingConfiguration.Apply(Configuration cfg)
at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration()

すべてのアセンブリは GAC にあります。それらを _app_bin または bin にコピーしようとしましたが、成功しませんでした。

アップデート

私を助けてください!私はこの奇妙な問題に悩まされています:(

4

1 に答える 1

0

私は解決策を見つけました。

私の構成行を見てください:

config = new Configuration();
config = config.Configure(specifiedConfigurationFilePath);
config = Fluently.Configure(config)
                 .Mappings(m => m.FluentMappings.AddFromAssemblyOf<ItemMap>())
                 .BuildConfiguration();

新しいnhibernate構成オブジェクトを作成して、それをfluent-nhibernate静的初期化メソッドに渡します。これは物事が起こるポイントです。Fluent-nhibernateは、指定されたファイルから構成を取得できません。代わりに、ファイルパスが指定されたnhibernate構成オブジェクトを取得し、それを使用して構成を構築できます。以前のバージョンのアプリケーションは1つのアセンブリに含まれており、この構成方法は正常に機能しているようです。しかし、アプリケーションを分割すると、問題が発生しました。したがって、問題を解決するには、web.configファイルからnhibernate構成情報を取得する必要があります。単一アセンブリプロジェクトの場合のように、タイマージョブとWebアプリケーションの設定を1つのファイルにマージできません。したがって、いくつかの構成ファイルが必要であり、常に次のような従来の行を使用する必要がありました。

Fluently
 .Configure()
  .Mappings(p => p.FluentMappings
                   .AddFromAssemblyOf<ItemMap>())
                    .BuildConfiguration()

それはある種の流暢で無邪気なバグか何かのようです...

于 2012-10-23T07:08:07.290 に答える