Naive Container 


Container could be very simple and easy 

Download 1.0 Version: 

NaiveContainer.dll 

NaiveContainer.zip 

Features

Simple to use

Minimal configuration and duplication

Do not bloat your constructor

Do not have injection setter

Drawback

dependency is implicit instead of explicit

Google Code

Go to project page


 Naive Demo:

Boy is a boy

public interface Boy
    {
        string Name { get; }
    }

Susan wants a boy 

public class Susan : ContainerBound
    {
        public void FallInLove()
        {
            Console.WriteLine("Susan has fallen in love with " + Get<Boy>().Name);
        }
    }

Lucy wants a boy

public class Lucy : ContainerBound
    {
        public void Marry()
        {
            Console.WriteLine("Lucy is marrying " + Get<Boy>().Name);
        }
    }

 Lily wants a boy

public class Lily : ContainerBound
    {
        public void Kiss()
        {
            Console.WriteLine("Lily is kissing {0}", Get<Boy>().Name);
        }
    }

You give girls the boy they want

Containers.GetContainerInContext<object>().Put(new GenericBoy("Van"));

Containers.GetContainerInContext<Lucy>().Put(new GenericBoy("Tom"));

Containers.GetContainerInContext<Lily>().Put(new GenericBoy("Joy"));

Containers.Close();

Now, show time 

new Susan().FallInLove();

new Lily().Kiss();

new Lucy().Marry(); 

Susan has fallen in love with Van
Lily is kissing Joy
Lucy is marrying Tom

Behind the scene

public class ContainerBound
    {
        protected T Get<T>()
        {
            return Containers.GetReadonlyContainerInContext(GetType()).Get<T>();
        }
    }

Sign in  |  Recent Site Activity  |  Terms  |  Report Abuse  |  Print page  |  Powered by Google Sites