Yes, this downsite is realy bad, and you should avoid it. In your case you can do something like this public class CustomUserNameValidator : UserNamePasswordValidator { public static CustomUserNameValidator Current { get; private set; } public CustomUserNameValidator() { Current = this; } public override void Validate(string userName, string password) { throw new FaultException("No pasaran"); } Dependency public ISomeService Service { get; set; } } It will be created only once for service when service host is created, so you should write following code using (ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService))) //here it will be created { container. BuildUp(CustomUserNameValidator.
Current); //here you can inject all you need } This is just inverted idea with static wrapper of the unity container :).
I'm hosting through IIS, so I'm guessing I could do the BuildUp in the constructor of the service contract. But there's still a downside to this as well, you have to publically expose your service... But I guess that's a lot better than exposing the entire container. – Dannerbo May 22 '10 at 17:33 On another note... Since I'm using a config file to map all my objects for Unity, is my original static idea still a concern?
Assume I don't use a static wrapper class around a unity container instance, I could still create a new UnityContainer anywhere in code and configure it using the config file and create any objects I wanted. So I'm not sure the UnityContainerWrapper idea is even creating an "issue", it's just making an existing issue more noticable? If that makes sense... – Dannerbo May 22 '10 at 18:25 probably, you have several assemblies, but only one is Unity aware - the most highlevel, so other can't create unitycontainer at all.
Second thing is lifetime management. I's realy a big risc to create two containers with singletons, becouse you can get the whole other behaviour then you expect. So this is sort of conventional things, but it make such a scenario very unlikable.
– er-v May 23 '10 at 5:30 I do agree, having just one assembly unity-aware would be nice... But in reality, aren't none of them?... Unless you're using strictly constructor injection? Because you have to tag all your dependencies with the Dependency attribute... So you have to reference the Unity assemblies anyway? Thoughts?
– Dannerbo May 25 '10 at 3:24.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.