I am going to preface this question with the statement: I know that the following is a bad design, but refactoring is currently not an option, ideally this should be done using sniffers.
I am working on updating the lock from 1.6 (I think) to 3.3, which, unfortunately, is associated with some syntax changes, now everything compiles for me, but some of my tests around the service container do not work.
I have a repository that has several implementations to provide various functions, the repository is used only in all different inline implementations, here are the basic information about the code:
Registering Castle Windsor:
RepositoryRegistration<IAccountRepository, AccountRepositoryFeedEntryDecorator>() .DependsOn(Dependency.OnComponent("decoratedRepository", typeof(AccountRepositoryAuthorizationDecorator))), RepositoryRegistration<AccountRepositoryAuthorizationDecorator>() .DependsOn(Dependency.OnComponent("decoratedRepository", typeof(AccountRepositoryMaskingDecorator))), RepositoryRegistration<AccountRepositoryMaskingDecorator>() .DependsOn(Dependency.OnComponent("decoratedRepository", typeof(AccountRepository))), RepositoryRegistration<AccountRepository>());
Repository Method:
private static ComponentRegistration<TRepository> RepositoryRegistration<TRepository, TConcreteRepository>() where TConcreteRepository : TRepository where TRepository : class { return Component .For<TRepository>() .ImplementedBy<TConcreteRepository>() .Named(typeof(TConcreteRepository).Name); }
Base interface:
public interface IAccountRepository { string Create(Account account); void Update(Account account); Account Get(string accountId); }
Implementations:
public class AccountRepositoryFeedEntryDecorator : IAccountRepository { private readonly IAccountRepository decoratedRepository; public AccountRepositoryFeedEntryDecorator( IAccountRepository decoratedRepository) { this.decoratedRepository = decoratedRepository; } string Create(Account account) { //Add Entry To Feed return decoratedRepository.Create(account); }; void Update(Account account) { //Add Entry To Feed return decoratedRepository.Udpate(account); } Account Get(string accountId); { //Add Entry To Feed return decoratedRepository.Get(accountId); } } public class AccountRepositoryAuthorizationDecorator : IAccountRepository { private readonly IAccountRepository decoratedRepository; public AccountRepositoryAuthorizationDecorator( IAccountRepository decoratedRepository) { this.decoratedRepository = decoratedRepository; } string Create(Account account) { //Ensure User Is Authorized return decoratedRepository.Create(account); }; void Update(Account account) { //Ensure User Is Authorized return decoratedRepository.Udpate(account); } Account Get(string accountId); { //Ensure User Is Authorized return decoratedRepository.Get(accountId); } } public class AccountRepositoryMaskingDecorator : IAccountRepository { private readonly IAccountRepository decoratedRepository; public AccountRepositoryMaskingDecorator( IAccountRepository decoratedRepository) { this.decoratedRepository = decoratedRepository; } string Create(Account account) { //Mask Sensitive Information return decoratedRepository.Create(account); }; void Update(Account account) { //Mask Sensitive Information return decoratedRepository.Udpate(account); } Account Get(string accountId); { //Mask Sensitive Information return decoratedRepository.Get(accountId); } } public class AccountRepository : IAccountRepository { string Create(Account account) { //Create account and return details }; void Update(Account account) { //Update account and return details } Account Get(string accountId); { //Return Account } }
And finally, here is the error I get in my test:
Castle.MicroKernel.Handlers.HandlerException: Cannot create the AccountRepositoryFeedEntryDecorator component because it has dependencies that must be satisfied.
'AccountRepositoryFeedEntryDecorator' expects the following dependencies: - The component "Shaw.Services.CustomerManagement.Host.Repositories.Sql.Decorators.AccountRepositoryAuthorizationDecorator" (through redefinition), which was registered but also expects dependencies.
'Shaw.Services.CustomerManagement.Host.Repositories.Sql.Decorators.AccountRepositoryAuthorizationDecorator expects the following dependencies: - The "AccountRepositoryFeedEntryDecorator" service, which has been registered but also waits for dependencies.
At first glance, it seems that there is some kind of cyclical dependence, but I can’t figure out how to do it.
So, the question is in two parts, what is the difference between the specification of the dependencies of the component and the service in the error message, any guesses about what is going wrong.
If that matters, this is the original registration before the upgrade:
RepositoryRegistration<IAccountRepository, AccountRepositoryFeedEntryDecorator>() .ServiceOverrides(new { decoratedRepository = typeof(AccountRepositoryAuthorizationDecorator).Name }), RepositoryRegistration<AccountRepositoryAuthorizationDecorator>() .ServiceOverrides(new { decoratedRepository = typeof(AccountRepositoryMaskingDecorator).Name }), RepositoryRegistration<AccountRepositoryMaskingDecorator>() .ServiceOverrides(new { decoratedRepository = typeof(AccountRepository).Name }), RepositoryRegistration<AccountRepository>()