How to inject dependencies into a custom UserNamePasswordValidator in WCF?

Posted by Dannerbo on Stack Overflow See other posts from Stack Overflow or by Dannerbo
Published on 2010-05-22T01:04:27Z Indexed on 2010/05/22 1:20 UTC
Read the original article Hit count: 318

I'm using a UserNamePasswordValidator in WCF along with Unity for my dependency injection, but since WCF creates the instance of the UserNamePasswordValidator, I cannot inject my container into the class. So how would one go about this?

The simplest solution I can think of is to create a static proxy/wrapper class around a static instance of a UnityContainer, which exposes all the same methods... This way, any class can access the container, and I don't need to inject it everywhere.

So I could just do UnityContainerWrapper.Resolve() anywhere in code. So basically this solution solves 2 problems for me, I can use it in classes that I'm not creating an instance of, and I can use it anywhere without having to inject the container into a bunch of classes.

The only downside I can think of is that I'm now potentially exposing my container to a bunch of classes that wouldn't of had access to the container before. Not really sure if this is even a problem though?

© Stack Overflow or respective owner

Related posts about wcf

Related posts about security