static void Main(string[] args) { HelloService helloService = new HelloService(); ConsumerService consumerService = new ConsumerService(helloService); consumerService.Print(); Console.ReadKey(); }
static void Main(string[] args) { HelloService helloService = (HelloService)Activator.CreateInstance(typeof(HelloService)); //动态创建对象HelloService ConsumerService consumerService = (ConsumerService)Activator.CreateInstance(typeof(ConsumerService), helloService); //动态创建对象ConsumerService consumerService.Print(); Console.ReadKey(); }
public ConsumerService(HelloService helloService) { this._helloService = helloService; }