static void Main(string[] args) { IOne[] arr = new IOne[] { new Payal(), new Priya() }; }
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; }
public void TestInterfaceQuestion() { var foobar = new FooBar(); IOne iOne = foobar; ITwo iTwo = foobar; // Pity: // IOneAndTwo iBoth = foobar; }
static void Main(string[] args) { A obj = new A(); //obj.f(); //Error!不能通过对象引用调用显式实现的接口方法 IOne iobj = obj; iobj.f(); //显式实现的接口方法只能通过接口变量调用 Console.ReadKey(); }
public static void Main() { Number n = new Number(); IOne one = n.GetNumberObject <One>(); one.PrintOne(); ITwo two = n.GetNumberObject <Two>(); two.PrintTwo(); }
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); }
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; }
public HasOne(IOne one) { One = one; }
public OneDecorator(IOne one) { }
public Two(IOne one) { }
public Some(IOne one, ITwo two) { this.one = one; this.two = two; }
public ServiceWithDependencies(IOne one, HasOne hasOne) { this.one = one; this.hasOne = hasOne; }
public ServiceWithDependencies(IOne one,HasOne hasOne) { this.one = one; this.hasOne = hasOne; }
public Pair(IOne one, ITwo two) : this() { One = one; Two = two; }
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)); }
public CMany(int id,IOne callbackRef) { m_Callback = callbackRef; }
public App(IOne iOneInstance, ITwo iTwoInstance) /* Irrelevant */ }