开发者

XML Config to initialize simple string in Unity

Newbie Microsoft Unity question.

How do I specify the config to initialize a simple string type.

I'm thinking of the below... but it doesn't like the char[] paramater in the constructor.

    <register type="string" name="myString" >
      <constructor&开发者_如何学Cgt;
        <param name="char[]" value="SomeValue">
        </param>
      </constructor>
    </register>


Why don't inject the URL into the object using it, instead of leaving it to call Resolve?

public interface IMyService { 
   void DoSomething();
}

public class MyServiceRemote : IMyService {

   private readonly _url;

   public MyServiceRemote(string url) {
     _url = url;
   }

   public void DoSomething() {
     ...
   }   

}

and, in the config:

<register type="IMyService" mapTo="MyServiceRemote" >
      <constructor>
        <param name="url" value="SomeValue">
        </param>
      </constructor>
</register>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜