Beispiel #1
0
        public void TestSingletonByName()
        {
            var container = new CryoContainer();

            container.RegisterSingleton <MyClazz>("MyClazz");

            Assert.IsNull(container.WeakResolveByName <MyClazz>("MyClazz"));
            var clazz = container.ResolveByName <MyClazz>("MyClazz");

            Assert.IsNotNull(clazz);

            var clazz2 = container.WeakResolveByName <MyClazz>("MyClazz");

            Assert.IsNotNull(clazz2);
            Assert.AreSame(clazz, clazz2);

            try
            {
                container.WeakResolve <MyClazz>();
                Assert.Fail("Exception expected");

                //ascxasxasxasx
            }
            catch (ContainerException)
            {
                return;
            }
        }
Beispiel #2
0
        public void TestSingletonByName()
        {
            var container = new CryoContainer();

            container.RegisterSingleton <MyClazz>("MyClazz");

            Assert.IsNull(container.TryResolveByName <MyClazz>("MyClazz"));
            var clazz = container.ResolveByName <MyClazz>("MyClazz");

            Assert.IsNotNull(clazz);

            var clazz2 = container.TryResolveByName <MyClazz>("MyClazz");

            Assert.IsNotNull(clazz2);
            Assert.AreSame(clazz, clazz2);

            Assert.IsNull(container.TryResolve <MyClazz>());
        }
Beispiel #3
0
        public void TestAiasWithName()
        {
            var container = new CryoContainer();

            container.RegisterSingleton <MainClass>();
            container.RegisterAlias <IFirstInterface, MainClass>("AliasWithName");

            var firstInterface = container.ResolveByName <IFirstInterface>("AliasWithName");
            var mainClass      = container.Resolve <MainClass>();

            Assert.AreSame(mainClass, firstInterface);

            try
            {
                container.Resolve <IFirstInterface>();
                Assert.Fail("Expected CryoDI.ContainerException : Can't resolve type CryoDI.Tests.IFirstInterface");
            }
            catch (ContainerException ex)
            {
                // expected CryoDI.ContainerException : Can't resolve type CryoDI.Tests.MainClass
            }
        }
Beispiel #4
0
 public T Resolve(params object[] parameters)
 {
     return(_container.ResolveByName <T>(_name, parameters));
 }
Beispiel #5
0
 public object GetObject(object owner, CryoContainer container, params object[] parameters)
 {
     return(container.ResolveByName <T>(_name, parameters));
 }