Exemplo n.º 1
0
        public void ThrowsOnReRegister()
        {
            var tiny = new TinyContainer();

            tiny.Register <Simple>();

            Assert.ThrowsException <TinyError>(() => tiny.Register <Simple>());
            Assert.ThrowsException <TinyError>(() => tiny.Register(factory => new Simple()));
        }
        protected override ContainerFor <T> CreateSut <T>()
        {
            var container = new TinyContainer();

            container.Register <IDependency1, Dependency1>();
            container.Register <IDependency2, Dependency2>();
            container.Register <ConcreteObjectWithNoConstructor>();
            container.Register <ConcreteObjectWithMultipleConstructors>();
            return(new ContainerFor <T>(container));
        }
Exemplo n.º 3
0
        public void Class()
        {
            var tiny = new TinyContainer();

            tiny.Register <Simple>();

            Assert.IsNotNull(tiny.Resolve <Simple>());
        }
Exemplo n.º 4
0
        public void WithFactory()
        {
            var tiny = new TinyContainer();

            tiny.Register(factory => new Simple());

            Assert.IsNotNull(tiny.Resolve <Simple>());
        }
Exemplo n.º 5
0
        public void Interface()
        {
            var tiny = new TinyContainer();

            tiny.Register <ISimple, Simple>();

            Assert.IsNotNull(tiny.Resolve <ISimple>());
        }
Exemplo n.º 6
0
        public void Delegate()
        {
            var tiny = new TinyContainer();

            tiny.Register <Simple>()
            .Register <Func <Simple> >(factory => factory.Resolve <Simple>);

            Assert.IsNotNull(tiny.Resolve <Func <Simple> >()());
        }
Exemplo n.º 7
0
        public void ComplexClass()
        {
            var tiny = new TinyContainer();

            tiny.Register <Simple>()
            .Register <ISimple, Simple>()
            .Register <Func <Simple> >(factory => () => new Simple())
            .Register <IComplex, Complex>();

            var simpleInstance = tiny.Resolve <IComplex>();

            Assert.IsNotNull(simpleInstance);
        }
 public static TinyContainer RegisterSignleton <TObject>(this TinyContainer container, TObject instance)
 {
     container.Register(typeof(TObject), new SingletonLifetimeManager(instance));
     return(container);
 }
 public static TinyContainer RegisterTransient <TMappedType, TActualType>(this TinyContainer container, string name = null)
 {
     container.Register(typeof(TMappedType), new TransientLifetimeManager(typeof(TActualType)));
     return(container);
 }