public static void Main(string[] args) { IOne one = new OneTwo(); ITwo two = one as ITwo; Console.WriteLine(two is IOne); Console.Read(); }
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; }
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 One(ITwo two) { }
public static string ParseValue(this ITwo ob) { return("Two"); }
public IApp Create(IOne iOneInstance, ITwo iTwoInstance) { return(this.iAppFactory(iOneInstance, iTwoInstance)); }
public ServiceWithSession(IOne one, ITwo two) { this.one = one; this.two = two; InstanceCount++; }
public App(IOne iOneInstance, ITwo iTwoInstance) /* Irrelevant */ }
public T Get(ITwo <T> b) { return(default(T)); }
public Pair(IOne one, ITwo two) : this() { One = one; Two = two; }
public Some(IOne one, ITwo two) { this.one = one; this.two = two; }