IChannelFactory<TChannel> and endpoint configuration from web.config
I have a WCF Ria service which invokes several wcf services (non Ria). I'm using ChannelFactory to create channels, but the problem is that I want to write unit tests for this Ria Service and ChannelFactory is a class, not an interface, so I can't mock开发者_JS百科 it. An ideal solution would be to declare IChannelFactory and use dependency injection, but there is a problem here.
ChannelFactory has an overload of CreateChannel which takes the name of endpoint configuration name defined in web/app.config file. I'm using that method, this way I don't have to hardcode endpoint parameters or create additional ConfigurationProperties to reinvent the wheel. IChannelFactory doesn't have this member, so even when I inject ChannelFactory into my service, I'm unable to create a channel configured from configuration file. So my question is, how to workaround this issue? I mean how to create a channel and configure it from configuration file using IChannelFactory contract without Reflection/dynamic?
Well, I found a solution by creating my own IChannelFactory. One of it's implementation relies on ChannelFactory and the other one is mocked :)
精彩评论