How can a static class be resolved by the Unity Framework?

Posted by user213988 on Stack Overflow See other posts from Stack Overflow or by user213988
Published on 2010-04-01T17:25:08Z Indexed on 2010/06/14 13:12 UTC
Read the original article Hit count: 233

Filed under:
|
|
|

I wold like the unity framework to resolve a static class "MyStaticObject" specified in my config file. As my class is static, I am getting an error "The type StaticObject does not have an accessible constructor."

My config file looks as below:

  <unity>
    <typeAliases>
      <typeAlias alias="singleton" type="Microsoft.Practices.Unity.ContainerControlledLifetimeManager, Microsoft.Practices.Unity" />
      <typeAlias alias="StaticObject" type="MyStaticAssembly.MyStaticObject, MyStaticAssembly, Version=1.0.0.0" />
      <typeAlias alias="staticobject" type="MyStaticAssembly.MyStaticObject, MyStaticAssembly" />
    </typeAliases>

    <containers>
      <container> 
        <types>
          <type type="StaticObject" mapTo="staticobject" name="My Static Object">
            <lifetime type="singleton"/>
          </type>
        </types>
      </container>
    </containers>
  </unity>

I would highly appreciate any help.

© Stack Overflow or respective owner

Related posts about .NET

Related posts about static