Ejemplo n.º 1
0
 static void Main(string[] args)
 {
     IOne[] arr = new IOne[]
     {
         new Payal(), new Priya()
     };
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 3
0
        public void TestInterfaceQuestion()
        {
            var  foobar = new FooBar();
            IOne iOne   = foobar;
            ITwo iTwo   = foobar;

            // Pity:
            // IOneAndTwo iBoth = foobar;
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            A obj = new A();
            //obj.f();  //Error!不能通过对象引用调用显式实现的接口方法
            IOne iobj = obj;

            iobj.f();   //显式实现的接口方法只能通过接口变量调用
            Console.ReadKey();
        }
Ejemplo n.º 5
0
    public static void Main()
    {
        Number n   = new Number();
        IOne   one = n.GetNumberObject <One>();

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

        two.PrintTwo();
    }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
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 Two(IOne one)
 {
     One = one;
 }
Ejemplo n.º 9
0
 public HasOne(IOne one)
 {
     One = one;
 }
Ejemplo n.º 10
0
 public OneDecorator(IOne one)
 {
 }
 public Two(IOne one)
 {
 }
 public Some(IOne one, ITwo two)
 {
     this.one = one;
     this.two = two;
 }
Ejemplo n.º 13
0
 public ServiceWithDependencies(IOne one, HasOne hasOne)
 {
     this.one    = one;
     this.hasOne = hasOne;
 }
Ejemplo n.º 14
0
		public HasOne(IOne one)
		{
			One = one;
		}
		public ServiceWithDependencies(IOne one,HasOne hasOne)
		{
			this.one = one;
			this.hasOne = hasOne;
		}
 public OneDecorator(IOne one)
 {
 }
Ejemplo n.º 17
0
 public Pair(IOne one, ITwo two) : this()
 {
     One = one;
     Two = two;
 }
Ejemplo n.º 18
0
 public ServiceWithSession(IOne one, ITwo two)
 {
     this.one = one;
     this.two = two;
     InstanceCount++;
 }
 public IApp Create(IOne iOneInstance, ITwo iTwoInstance)
 {
     return(this.iAppFactory(iOneInstance, iTwoInstance));
 }
Ejemplo n.º 20
0
 public CMany(int id,IOne callbackRef)
 {
   m_Callback = callbackRef;
 }
Ejemplo n.º 21
0
		public ServiceWithSession(IOne one, ITwo two)
		{
			this.one = one;
			this.two = two;
			InstanceCount++;
		}
 public App(IOne iOneInstance, ITwo iTwoInstance) /* Irrelevant */ }