我有这个代码,是依赖注入还是没有?我想通过接口从不同的来源获取数据。
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
Data D = new Data();
AnotherApplication AS = new AnotherApplication(D);
Console.ReadKey();
}
}
public interface IData
{
WebSocket WebSocket { get; }
}
public class Data:IData
{
public WebSocket WebSocket
{
get
{
var temp = new WebSocket("ws://127.0.0.1:2012");
temp.Open();
return temp;
}
}
}
public class AnotherApplication
{
public AnotherApplication(IData source)
{
source.WebSocket.MessageReceived += ProcessMessage;
}
public void ProcessMessage(object o,EventArgs e)
{
Console.WriteLine("Another happening");
}
}
}