2011-02-03 16 views
1

AccountService,UserServiceDocumentServiceなどのサービスを含むアプリケーションレイヤーがあります。サービス内でサービスを呼び出す

私のサービスのコンストラクタは次のようになりますので、私は私の依存性の注入のためのStructureMapを使用

:私は次のことを持っていることがあります良い形でながらUserServic電子を言うためにアクセスする必要がある場合は今

public AccountService(IAccountRepository repo) 
{ 
    this.accountRepository = repo; 
} 

public AccountService(IAccountRepository repo, IUserService user) 
{ 
    this.accountRepository = repo; 
    this.userService = user; 
} 

答えて

0

はい、完璧です。コードをダウンロードして、episodes Rob Coneryが用意したものを見ることができます。

public class CatalogService : Commerce.Services.ICatalogService 
{ 
    ICatalogRepository _repository = null; 
    IOrderService _orderService = null; 

    /// <summary> 
    /// Creates a CatalogService based on the passed-in repository. 
    /// </summary> 
    /// <param name="repository">An ICatalogRepository</param> 
    public CatalogService(
     ICatalogRepository repository, IOrderService orderService) 
    { 
     _repository = repository; 
     _orderService = orderService; 

     if (_repository == null) 
      throw new InvalidOperationException("Repository cannot be null"); 
    } 
    ... 
} 

彼はCatalogServiceにOrderServiceを注入します。

関連する問題