private SunsetLake GetSepLake(Dictionary <string, object> args) { SunsetLake s_lake = new SunsetLake(); s_lake.RegisterSingleton <ILogger>(LoggerFactory.Auto(this.GetType().Name)); s_lake.RegisterSingleton <ClassTextReader>(() => { return(ClassTextReaderCache.Acquire(this.GetType())); }); s_lake.RegisterSingleton <IExtensionInfo>(() => { return(this.GetExtensionInfo()); }); s_lake.RegisterSingleton <ILeafUI>(() => { ILeafUI leafUI = this.lake !.Get <ILeafUI>(); IExtensionInfo inf = this.GetExtensionInfo(); leafUI.Title = inf.Name(); leafUI.Icon = inf.Icon(); return(leafUI); }); s_lake.RegisterSingleton <Dictionary <string, object> >(() => { return(args ?? new Dictionary <string, object>()); }); return(s_lake); }
public void FieldTest() { SunsetLake lake = new SunsetLake(); lake.RegisterSingleton(FieldInjectTarget.TEST_STR_ID, () => FieldInjectTarget.TEST_STR); lake.RegisterSingleton <FieldInjectTarget, FieldInjectTarget>(); var target = lake.Get <FieldInjectTarget>(); Assert.IsTrue(target.IsAllRight()); }
public void RegisterSingletonTest() { IRegisterableLake lake = new SunsetLake(); lake.RegisterSingleton(typeof(int), () => 1); lake.RegisterSingleton <string>("test string"); Assert.IsTrue(lake.Get <int>() == 1); Assert.IsTrue(lake.Get <string>() == "test string"); }
public void InjectingTest() { IRegisterableLake lake = new SunsetLake(); const int TEST_SUM = 50; const string TEST_STR = "test str"; lake.RegisterSingleton("sum", () => TEST_SUM); lake.RegisterSingleton <string>(TEST_STR); lake.RegisterSingleton <InjectTestClass, InjectTestClass>(); var testClass = lake.Get <InjectTestClass>(); Assert.IsTrue(testClass.Sum == TEST_SUM); Assert.IsTrue(testClass.Str == TEST_STR); }
public void ObjectBuildTest() { const int sum = 5; const string str = "test string"; IRegisterableLake lake = new SunsetLake(); lake.RegisterSingleton <int>(sum); lake.RegisterSingleton <string>(str); lake.RegisterSingleton <ITestInterface, TestClass>(); ITestInterface testInterfaceImpl = lake.Get <ITestInterface>(); Assert.IsTrue(testInterfaceImpl.Str == str); Assert.IsTrue(testInterfaceImpl.Sum == sum); }
public void GetComponentsCompatibilitTest() { IRegisterableLake lake = new SunsetLake(); lake.RegisterSingleton("t", "2401"); Assert.AreEqual("2401", lake.GetComponents("t").FirstOrDefault()); }
public void ByTypeInject() { const string TEST_STR = "test string"; SunsetLake lake = new SunsetLake(); lake.RegisterSingleton <string>(TEST_STR); var instance = new InjectTarget(); new DependenciesInjector(instance, lake).Inject(); Assert.IsTrue(instance.Str == TEST_STR); }
public void MixArgsTest() { const string TEST_STR = "test string"; const int SUM = 3; SunsetLake lake = new SunsetLake(); lake.RegisterSingleton <string>("f**k"); SunsetLake lake2 = new SunsetLake(); lake.RegisterSingleton <string>(TEST_STR); MethodProxy maxProxy = new MethodProxy(this, nameof(HashCodeAdd), lake + lake2); long result = (long)maxProxy.Invoke(new Dictionary <string, object>() { { "x", 3 } }); long correctResult = HashCodeAdd(SUM, TEST_STR); Assert.IsTrue(correctResult == result); }
private ILake GetSepLake() { SunsetLake s_lake = new SunsetLake(); s_lake.RegisterSingleton <ILogger>(LoggerFactory.Auto(this.GetType().Name)); s_lake.RegisterSingleton <ClassTextReader>(() => { return(ClassTextReader.GetReader(this)); }); s_lake.RegisterSingleton <IExtensionInfo>(() => { return(this.GetExtensionInfo()); }); s_lake.RegisterSingleton <ILeafUI>(() => { ILeafUI leafUI = this.lake !.Get <ILeafUI>(); IExtensionInfo inf = this.GetExtensionInfo(); leafUI.Title = inf.Name(); leafUI.Icon = inf.Icon(); return(leafUI); }); return(s_lake); }