internal Binder(Key bindedKey, CoolDI di, bool isExampleBind, bool isSingleton) { BindedKey = bindedKey; DI = di; IsExampleBind = isExampleBind; IsSingleton = isSingleton; }
public void CoolDISeeCommentsIntTest01() { CoolDI di = new CoolDI(); di.BindDefault <IClass3>().To <Class3>(); var class3 = di.GetDefault <IClass3>(); Assert.IsTrue(class3 is Class3); }
public void CoolDISeeCommentsIntTest10() { CoolDI di = new CoolDI(LateBindingOptions.MaxCtor, true); di.BindDefault <Class10>().ToDelegateWOArgs(() => new Class10("Hey!")); var class6 = di.GetDefault <Class6>(); Assert.IsTrue(class6 is Class6 && class6.Class9.Class10.SomeString == "Hey!" && class6.Class7.Class8 != null); }
public void CoolDISeeCommentsIntTest03() { CoolDI di = new CoolDI(); di.BindDefault <IClass1>().To <Class1>(); di.BindDefault <IClass2>().To <Class2>(); di.BindDefault <IClass3>().To <Class3>(); di.BindDefault <IClass4>().To <Class4>(); di.BindDefault <IClass5>().ToDelegateWithArgs((args) => new Class5((string)args[0])); Assert.ThrowsException <WrongParametersException>(() => di.GetDefault <IClass1>()); }
public void CoolDISeeCommentsIntTest04() { CoolDI di = new CoolDI(); di.BindDefault <IClass4>().ToDelegateWithArgs((args) => new Class4(di.GetDefault <IClass5>(args))); di.BindDefault <IClass5>().ToDelegateWithArgs((args) => new Class5((string)args[0])); object[] array = new object[1] { "Hey!" }; var class4 = di.GetDefault <IClass4>(array); Assert.IsTrue(class4 is Class4 && class4.Class5.SomeString == "Hey!"); }
public void CoolDISeeCommentsIntTest02() { CoolDI di = new CoolDI(); di.BindDefault <IClass1>().To <Class1>(); di.BindDefault <IClass2>().To <Class2>(); di.BindDefault <IClass3>().To <Class3>(); di.BindDefault <IClass4>().To <Class4>(); di.BindDefault <IClass5>().ToDelegateWOArgs(() => new Class5("Hey!")); var class1 = di.GetDefault <IClass1>(); Assert.IsTrue(class1 is Class1 && class1.Class4.Class5.SomeString == "Hey!" && class1.Class2.Class3 != null); }
public void CoolDISeeCommentsIntTest06() { CoolDI di = new CoolDI(); di.BindDefault <IClass5>().ToDelegateWithArgs((args) => new Class5((string)args[0])); object[] array = new object[1] { "Hey!" }; var var1 = di.GetDefault <IClass5>(array); var var2 = di.GetDefault <IClass5>(array); var var3 = di.GetDefault <IClass5>(array); Assert.IsTrue(var1 is Class5 && var2 is Class5 && var3 is Class5); Assert.IsFalse(Equals(var1, var2) || Equals(var2, var3)); }
private static IFileHandler InstantiateDefaultFileHandlerByCoolDI() { var di = new CoolDI(); di.BindDefaultAsSingleton <AppSettingsReader>().ToSelf(); di.BindDefault <ISmtpHandler>().ToDelegateWOArgs(() => { AppSettingsReader appSettingsReader = di.GetDefault <AppSettingsReader>(); string mail = (string)appSettingsReader.GetValue("OurMailAddress", typeof(string)); string host = (string)appSettingsReader.GetValue("Host", typeof(string)); int port = (int)appSettingsReader.GetValue("Port", typeof(int)); SmtpDeliveryMethod method = (SmtpDeliveryMethod)appSettingsReader.GetValue("SMTPDeliveryMethod", typeof(int)); string ourMailPassword = (string)appSettingsReader.GetValue("OurMailPassword", typeof(string)); bool enableSsl = (bool)appSettingsReader.GetValue("EnableSSL", typeof(bool)); return(new SmtpHandler(host, port, method, new NetworkCredential(mail, ourMailPassword), enableSsl)); }); di.BindDefault <ISendingFileFactory>().To <SendingFileFactory>(); di.BindDefault <IFileSender>().ToDelegateWOArgs(() => { AppSettingsReader appSettingsReader = di.GetDefault <AppSettingsReader>(); string ourMail = (string)appSettingsReader.GetValue("OurMailAddress", typeof(string)); string targetMail = (string)appSettingsReader.GetValue("TargetMailAddress", typeof(string)); return(new FileSender(ourMail, targetMail, di.GetDefault <ISmtpHandler>(), di.GetDefault <ISendingFileFactory>())); }); di.BindDefault <IFileManipulator>().To <FileManipulator>(); di.BindDefault <IFileWatcher>().ToDelegateWOArgs(() => { AppSettingsReader appSettingsReader = di.GetDefault <AppSettingsReader>(); string mailToSendFolderPath = (string)appSettingsReader.GetValue("MailToSendFP", typeof(string)); NotifyFilters notifyFilter = (NotifyFilters)appSettingsReader.GetValue("NotifyFilter", typeof(int)); string filter = (string)appSettingsReader.GetValue("Filter", typeof(string)); return(new FileWatcher(mailToSendFolderPath, filter, notifyFilter, di.GetDefault <IFileManipulator>())); }); di.BindDefault <ILog>().ToDelegateWOArgs(() => LogManager.GetLogger(typeof(FileHandler))); di.BindDefault <IFileHandler>().ToDelegateWOArgs(() => { AppSettingsReader appSettingsReader = di.GetDefault <AppSettingsReader>(); string mailToSendFolderPath = (string)appSettingsReader.GetValue("MailToSendFP", typeof(string)); string invalidMailFolderPath = (string)appSettingsReader.GetValue("InvalidMailFP", typeof(string)); return(new FileHandler( mailToSendFolderPath, invalidMailFolderPath, di.GetDefault <IFileWatcher>(), di.GetDefault <IFileManipulator>(), di.GetDefault <IFileSender>(), di.GetDefault <ILog>())); }); return(di.GetDefault <IFileHandler>()); }
public void CoolDISeeCommentsIntTest09() { CoolDI di = new CoolDI(); Assert.ThrowsException <UnbindedTypeException>(() => di.GetExample <Class3>(1)); }
public void CoolDISeeCommentsIntTest08() { CoolDI di = new CoolDI(); Assert.ThrowsException <UnbindedTypeException>(() => di.GetDefault <Class3>()); }
public void CoolDISeeCommentsIntTest07() { CoolDI di = new CoolDI(); Assert.ThrowsException <ArgumentException>(() => di.BindExample <Class5>(0).ToSelf()); }