예제 #1
0
        public static void  Main(string[] args)
        {
            IOne one = new OneTwo();
            ITwo two = one as ITwo;

            Console.WriteLine(two is IOne);
            Console.Read();
        }
예제 #2
0
 public MyCalculator([Named("Val")] IOne oneFirst, [Named("ED")] IOne oneSecond,
                     [Named("Val")] ITwo twoFirst, [Named("ED")] ITwo twoSecond, IThree three)
 {
     _oneFirst  = oneFirst;
     _oneSecond = oneSecond;
     _twoFirst  = twoFirst;
     _twoSecond = twoSecond;
     _three     = three;
 }
예제 #3
0
        public void TestInterfaceQuestion()
        {
            var  foobar = new FooBar();
            IOne iOne   = foobar;
            ITwo iTwo   = foobar;

            // Pity:
            // IOneAndTwo iBoth = foobar;
        }
예제 #4
0
    public static void Main()
    {
        Number n   = new Number();
        IOne   one = n.GetNumberObject <One>();

        one.PrintOne();
        ITwo two = n.GetNumberObject <Two>();

        two.PrintTwo();
    }
예제 #5
0
        public string Display()
        {
            string consoleText = "";

            Example exampleInstance = new Example();

            IOne exampleIOne = exampleInstance;
            ITwo exampleITwo = exampleInstance;

            consoleText += DisplayFormatHelpers.DescriptionValueFormat(
                "Accessing the method explicitly using the type of the variable",
                exampleIOne.SaySomething()
                );


            consoleText += DisplayFormatHelpers.DescriptionValueFormat(
                "Accessing the method explicitly by type casting the class itself",
                ((ITwo)exampleInstance).SaySomething()
                );

            return(consoleText);
        }
예제 #6
0
    void Main()
    {
        IUnityContainer container = new UnityContainer();

        container.RegisterType <IOne, OneA>("A");
        container.RegisterType <IOne, OneB>("B");
        container.RegisterType <ITwo, TwoA>("A");
        container.RegisterType <ITwo, TwoB>("B");
        container.RegisterType <Func <IOne, ITwo, IApp> >(
            new InjectionFactory(c =>
                                 new Func <IOne, ITwo, IApp>((iOne, iTwo) =>
                                                             c.Resolve <IApp>(
                                                                 new ParameterOverride("iOneInstance", iOne),
                                                                 new ParameterOverride("iTwoInstance", iTwo)))));
        container.RegisterType <Func <string, string, IApp> >(
            new InjectionFactory(c =>
                                 new Func <string, string, IApp>((iOneNamedRegistration, iTwoNamedRegistration) =>
                                                                 c.Resolve <IApp>(
                                                                     new ParameterOverride("iOneInstance", c.Resolve <IOne>(iOneNamedRegistration)),
                                                                     new ParameterOverride("iTwoInstance", c.Resolve <ITwo>(iTwoNamedRegistration))))));
        // Alternate writing
        container.RegisterType <Func <string, string, IApp> >(
            new InjectionFactory(c =>
                                 new Func <string, string, IApp>((iOneNamedRegistration, iTwoNamedRegistration) =>
        {
            IOne iOne = c.Resolve <IOne>(iOneNamedRegistration);
            ITwo iTwo = c.Resolve <ITwo>(iTwoNamedRegistration);
            IApp iApp = c.Resolve <IApp>(
                new ParameterOverride("iOneInstance", iOne),
                new ParameterOverride("iTwoInstance", iTwo));
            return(iApp);
        })));
        ClassWithFactoryMethodOne versionOne = container.Resolve <ClassWithFactoryMethodOne>();
        // Somewhere you have logic and end up with instances of IOne and ITwo then you :
        IApp iApp1 = versionOne.Create(iOneInstance, iTwoInstance);     // This doesn't compile cause you'd need the instances.
        ClassWithFactoryMethodTwo versionTwo = container.Resolve <ClassWithFactoryMethodTwo>();
        IApp iApp2 = versionTwo.Create("A", "B");
    }
 public One(ITwo two)
 {
 }
예제 #8
0
 public static string ParseValue(this ITwo ob)
 {
     return("Two");
 }
 public IApp Create(IOne iOneInstance, ITwo iTwoInstance)
 {
     return(this.iAppFactory(iOneInstance, iTwoInstance));
 }
예제 #10
0
		public ServiceWithSession(IOne one, ITwo two)
		{
			this.one = one;
			this.two = two;
			InstanceCount++;
		}
 public App(IOne iOneInstance, ITwo iTwoInstance) /* Irrelevant */ }
예제 #12
0
 public T Get(ITwo <T> b)
 {
     return(default(T));
 }
예제 #13
0
 public Pair(IOne one, ITwo two) : this()
 {
     One = one;
     Two = two;
 }
 public Some(IOne one, ITwo two)
 {
     this.one = one;
     this.two = two;
 }
예제 #15
0
 public ServiceWithSession(IOne one, ITwo two)
 {
     this.one = one;
     this.two = two;
     InstanceCount++;
 }