Привет, имею готовый код но не знаю, как применить Ninject Буду очень благодарен за помощь | Код | class CheckAccess:ICheck { public string Ping(string url) { #pragma warning disable HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create(url); httpReq.AllowAutoRedirect = false; HttpWebResponse httpRes = (HttpWebResponse)httpReq.GetResponse(); if (httpRes.StatusCode == HttpStatusCode.NotFound) { return "Not"; } else { return "Ok"; } httpRes.Close(); #pragma warning restore } }
|
| Код | interface ICheck { string Ping(string url); }
|
| Код | class FileOutput:IData { public void WriteData(string data) { string curFile = @"c:\temp\test.txt"; Console.WriteLine(File.Exists(curFile) ? "File exists." : "File does not exist."); Console.ReadKey(); }
internal void WriteData() { throw new NotImplementedException(); } }
|
| Код | interface IData { void WriteData(string data); }[IMG]http://[/IMG]
|
| Код | class Factory { public IData Show(ConsoleKey key) { switch (key) { case ConsoleKey.D1: return new ConsoleOutput(); case ConsoleKey.D2: return new FileOutput(); case ConsoleKey.D3: return new MixedOutput(); default: return new ConsoleOutput(); } } }
|
| Код | class ConsoleOutput:IData { public void WriteData(string data) { Console.WriteLine(data); Console.ReadLine(); } }
|
| Код | class MixedOutput:IData { private readonly ConsoleOutput _consoleOutput = new ConsoleOutput(); private readonly FileOutput _fileOutput = new FileOutput();
public void WriteData(string data) { _consoleOutput.WriteData(data); _fileOutput.WriteData(data); } }
|
| Код | class MyNinject:NinjectModule { public override void Load() { this.Bind<ICheck>().To<CheckAccess>(); } }
|
| Код | class Program { private static readonly CheckAccess chk = new CheckAccess();
public static IKernel AppKernel;
static void Main(string[] args) { AppKernel=new StandardKernel(new MyNinject()); var myvar = AppKernel.Get<FileOutput>(); myvar.WriteData(); var factory = new Factory(); var result = chk.Ping("http://www.dou.ua");
// If 1 - write to console // If 2 - write to file // If 3 - both // If Esc - exit while (true) { var key = Console.ReadKey(); if (ConsoleKey.Escape == key.Key) { return; } var outputer = factory.Show(key.Key); outputer.WriteData(result); } } } }
|
Может я не верно написал в классе MyNinject?
|