I have a little problem resolving types with Unity.
There’s an example of what I want to do:
public class MainClass
{
public void MainMethod()
{
UnityContainerHelper.DefaultContainer.Resolve<FirstClass>(new ParameterOverride("Property1", "SomeValue"));
UnityContainerHelper.DefaultContainer.Resolve<FirstClass>(new ParameterOverride("Property1", "OtherValue"));
}
}
public class FirstClass
{
[InjectionMethod]
public void DoSomething(SecondClass sc)
{
}
}
public class SecondClass
{
public string Property1 { get; set; }
[InjectionMethod]
public void DoSomething()
{
UnityContainerHelper.DefaultContainer.Resolve<ThirdClass>(this.Property1);
}
}
public class ThirdClass
{
}
EDIT: Is there a way to configure Unity to resolve my ThirdClass by name, when I’m resolving my FirstClass?
The problem is that I only want to explicitly resolve FirstClass, and by configuration, tell Unity that “use that ThirdClass” when resolving the SecondClass. Am I clear?
I’m trying to do a “resolving layer” to do this stuff, but I wonder if there is a simple way to do it.
You could tell to Unity to use Factory Methods to resolve your classes the way you want…
look at:
https://bitbucket.org/ctavares/unityfactoryconfig/downloads
i got from:
http://unity.codeplex.com/discussions/219565?ProjectName=unity