简体   繁体   中英

Register multiple endpoints of same contract in WCF and Castle windsor

I'm looking for some help on implementing WCF Castle injection in one of my projects

Basically, we are developing an configuration tool which would synchronize the data between our test and production environments. It would read the data from production environment and will update the data in test environments so that the test and production environments are in sync for regression testing of our applications

So, in my application configuration file, i'm maintaining different endpoints of my service (they have different names but have same contract). I'm registering them as follows

container.Register(Component.For<IService>().ImplementedBy<CustomServiceProxy>().Named(integration));
container.Register(Component.For<IService>().ImplementedBy<CustomServiceProxy>().Named(useracceptance));

The class "CustomServiceProxy" has business logic and does the data comparisons for synchronization.

In the above code, when the components are registering, I'm facing the below exception. I have verified the endpoints mentioned in the configuration file and all the endpoints are provided with a different names so that they don't conflict each other during runtime

An endpoint configuration section for contract 'DataSynch.IService' could not be loaded because more than one endpoint configuration for that contract was found. Please indicate the preferred endpoint configuration section by name

My idea is to register multiple service endpoints with different dependency names and use the registered names as keys to resolve the dependencies during run time using service overrides

container.Register(Component.For<IServiceFactory<IService>>().ImplementedBy<ServiceFactory>().
                        ServiceOverrides(
                            ServiceOverride.ForKey(IntService).Eq(integration),
                            ServiceOverride.ForKey(UatService).Eq(useracceptance)));     

The same keys mentioned in the service override are being passed to constructor parameters for dependency resolutions

Any quick help on this topic would be really helpful

I have found a way to address this problem using Castle Windsor Interceptors.

We register the interceptors for the dependencies and when the dependencies are resolved during run time, Castle takes care of adding the custom logic introduced as part of interceptors.

Tutorial link: https://lukemerrett.com/aop-in-castle-windsor/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM