1

Service/IService を拡張して、個々のサービスがハンドルを取得する必要がある他の DB 接続やカスタム クラスなどの追加リソースを登録できるようにする必要があります。

Service をサブクラス化する適切な方法はありますか? また、別の (たとえば) IDbConnection がある場合、Funq がどのプロパティに値を挿入するかをどのように判断するかは明確ではありません。

4

2 に答える 2

2

同じタイプのサービスが複数ある場合は、名前を付けて funq に登録する必要があります。残念ながら、funq はプロパティを正しく自動配線できないと思うので、手動で解決する必要があります。

    container.Register<DataContext>("Security", x => new SecurityDataContext());
    container.Register<DataContext>("Customers", x => new CustomersDataContext());
    container.Register<DataContext>("Reporting", x => new ReportingDataContext());

    container.Register<IReportRepository>(x => new ReportRepositoryImpl(x.ResolveNamed<DataContext>("Reporting")));

別のアプローチは、型ごとに (メンバーがなくても) 一意のインターフェイスを作成し、それを funq で使用することです。これにより、自動配線が可能になります

    container.Register<ISecurityDataContext>(x => new SecurityDataContext());
    container.Register<ICustomersDataContext>(x => new CustomersDataContext());
    container.Register<IReportingDataContext>(x => new ReportingDataContext());

    // これは単に自動配線することができます
    container.Register<IReportRepository>(x => new ReportRepositoryImpl(x.Resolve<IReportingDataContext>()));

それでも Service を拡張する必要がある場合は、C# で標準の継承を使用できます。

    パブリック抽象クラス BaseService : サービス
    {
         // カスタムはここに入る
         パブリック文字列の例() {
             「Hello World」を返します。
         }
    }

    public class ReportsService : BaseService
    {
        public string Get(ListReports リクエスト) {
            戻り値の例();
        }
    }
于 2013-09-06T13:39:52.777 に答える
0

AppHost.csService を拡張せずに他の DB 接続を簡単に構成できますが、ファイルの configure メソッドで接続するだけです。

于 2013-09-06T13:00:30.720 に答える