+
Skip to content

How to Resolve Generic Class<T>(it's constructor parameter also generic…e.g:Param<T> param) With Unity Container?? help! thanks #27

@jetjo

Description

@jetjo
interface Interface<T>{}

class Class<T>:Interface<T>
{
      public Class(IInterfaceParam<T> param){}
}

interface IInterfaceParam<T>{}

class InterfaceParam<T>:IInterfaceParam<T>{}

class Tclass{}

 class Program
 {
          void Main(){
                  var v1= container.Resolve<Interface<Tclass>>();
          }
 }

how to config in unity.config xml file?? help! thanks!

bellow is my config:

  <register type="IInterfaceParam`1" mapTo="InterfaceParam`1" name="paramDefault">
  </register>

  <register type="Interface`1" mapTo="Class`1">
    <constructor>
      <param type="IInterfaceParam`1" name="param">
        <dependency name="paramDefault"></dependency>
      </param>
    </constructor>
  </register>

but i got the exception:InvalidOperationException: Configuration is incorrect, the type Class`1 does not have a constructor that takes parameters named param...why???

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载