开发者

XML Config to initialize simple string in Unity

开发者 https://www.devze.com 2023-03-09 02:23 出处:网络
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.

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

精彩评论

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