开发者

Dependency injection with web services?

开发者 https://www.devze.com 2023-01-03 15:53 出处:网络
I\'ve recently discovered a possible candidate for dependency injection in a .Net application I开发者_开发百科\'ve designed.

I've recently discovered a possible candidate for dependency injection in a .Net application I开发者_开发百科've designed.

Due to a recent organizational policy, it is no longer possible to call smtp mail services from client machines on our network. So I'm going to have to refactor all the code in my application where it was previously calling the smtp object to send out mail.

I created a new WCF web service on an authorized web server that does allow for smtp mail messaging.

This seems to be a great candidate for dependency injection. I will create a new INotification interface that will have a method like 'void SendNotification(MailMessage msg)' and create a new property in my application where you can set this property to any class that implements this interface.

My question tho, is whether it's possible, through dependency injection, to encapsulate the instantiation of a .NET WCF web service? I am fairly new at IoC and Dependency injection frameworks, so I am not quite sure if it can handle web service dependencies?

I'm hoping someone else out there has come across this situation or has knowledge regarding this subject?

cheers, John


Yes, it's definitely possible to wire up a WCF service with Constructor Injection.

You can also use DI with WCF clients.

That said, the scenario sounds strange. If you aren't allowed to remotely connect to the SMTP server, why would you be allowed to remotely connect to the same machine over SOAP?


Ninject is a IoC container and there's an extension which targets WCF.

Grz, Kris.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号