Recursive Service Dependency Call Fails

Topics: Web Client Software Factory, UIP Application Block discussion, User Forum
Dec 7, 2007 at 4:43 AM
Team,
Our team just came acorss a situtation like this.

We have a shared service class like this'

 
public Class SharedDataService: ISharedDataService
{
    private readonly Database _database; // Uses Microsoft Data Access Block.
    
    public SharedDataService([CreateNew] Database database)
    {
       _database = database;
    }
    // Other methods 
}
 
// Note : This shared data service is added to container as a global one at the ShellModule level.
 
Now say we are having another module called as FinanaceModule and that has its own data service which uses the above shared data service.
 
public class FinanceDataService : IFinanceDataService
{
    private readonly SharedDataService _sharedDataService; 
     public FinanceDataService ([ServiceDependency] ISharedDataService  sharedDataService)
     {
          _sharedDataService = sharedDataService;
     }
 
    // Other methods 
}
 
// Note: The above structure compiles with out the problem. 
// Then we added the FinanceDataService to the Container at the Finance Module level using addModuleService call in the FinanceModuleInitializer class.
 

During run time what happens is, It tries to create a copy of FinanceDataService. During that process it sees SharedDataService and it tries to create a new one and add. Since the SharedDataService is created and added at the shellModule level, it gives and exception

So the question here is, How to avoid this problem. Another design question is, Is it best to chain the service dependency calls like the above example? The idea we thought of here is SharedDataService is the one which has all the methods like ExecuteScalar, ExecuteQuery and so and so forth which interacts with MS DAB. So at any point of we need to move towards a new Data Access tech, we just need to make changes to SharedDataService. Rest all are bound to work provided we make no changes to the ISharedDataService.

Please share your thoughts on this.

Best
Shibu Raj