I am developing WPF application using Prism framework. Let's begin.
I have a simple class Person
and I would like to create an object for static field staticObject
of property StaticObject
.
public class Person
{
IUnityContainer unityContainer;
public Person(IUnityContainer _unityContainer)
{
unityContainer=_unityContainer;
}
private static Person staticObject = unityContainer.Resolve<Person>;//here
//unityContainer is always NULL as constructor is called AFTER this statement
public static Person StaticObject
{
get { return staticObject; }
set { staticObject = value; }
}
}
What I've tried to do, but caught an error "The type name ‘StaticObject’ does not exist in the type ‘Person’", is:
public class MyModule : ModuleBase
{
Container.RegisterType<Person.StaticObject>(new ContainerControlledLifetimeManager());
//The line above it is not working.
//Error is "The type name ‘StaticObject’ does not exist in the type ‘Person’"
}
Is it possible to resolve UnityContainer for static property?
Update:
Cause I am using AvalonDock to create dockingable UI, so I cannot avoid using a static property (I've tried to avoid using a static property but I've not found a chance to avoid the static property).
Here a static property "This" which is used everywhere in AvalonDock Test example.
class Workspace : ViewModelBase
{
static Workspace _this = new Workspace(regionManager);
public static Workspace This
{
get { return _this; }
}
}
So this is a stumbling block for me to use UnityContainer. I cannot figure out how can I solve this task.