public void RunRegisteredInstancesWithContainerTest() { Console.WriteLine("Creating new unity container..."); IUnityContainer container = new UnityContainer(); Console.WriteLine("Registering fun stuff..."); FunContainers.RegisterFunStuffForRegisterTest(container); Console.WriteLine("Resolving fun stuff..."); IClown clown = container.Resolve <IClown>(); clown.ClownName = "Bubbles"; Console.WriteLine($"Clowns name is: {clown.ClownName}"); IElephant elephant = container.Resolve <IElephant>(); elephant.ElephantName = "Barbar"; Console.WriteLine($"The elephants name is: {elephant.ElephantName}"); IToilet toilet = container.Resolve <Toilet>(); Console.WriteLine($"The toilet is hiding here: {toilet.ToiletLocation}"); ICircus circus = container.Resolve <ICircus>(new ParameterOverride("clown", clown), new ParameterOverride("elephant", elephant), new ParameterOverride("location", "Some Place Imaginary")); Console.WriteLine("Executing circus methods..."); Console.WriteLine(circus.GetLocation()); circus.MakeElephantDoSomethingWithClown(); }
static void Main(string[] args) { IClown fingersTheClown = new ScaryScary("big red nose", 14); fingersTheClown.Honk(); if (fingersTheClown is IScaryClown scaryClown) { scaryClown.ScareLittleChildren(); } IClown.CarCapacity = 18; Console.WriteLine(IClown.ClownCarDescription()); }
static void Main(string[] args) { IClown.CarCapacity = 18; Console.WriteLine(IClown.ClownCarDescription()); IClown fingersTheClown = new ScaryScary("big red nose", 14); fingersTheClown.Honk(); if (fingersTheClown is IScaryClown iScaryClownReference) { iScaryClownReference.ScareAdults(); } }
static void Main(string[] args) { IClown[] clowns = new IClown[2]; TallGuy tallGuy = new TallGuy("A guitar") { Name = "Jimmy", Height = 74 }; clowns[0] = tallGuy; tallGuy.TalkAboutYourself(); Console.WriteLine(tallGuy.FunnyThingIHave); tallGuy.Honk(); Console.WriteLine(tallGuy.AnotherFunnyThingIHave); IClown tallClown = new TallGuy("A red nose"); clowns[1] = tallClown; tallClown.Honk(); Console.WriteLine("=============================="); Chief chief = new Chief(clowns); chief.GiveMeYourStuff(); Console.ReadKey(); }
string WhichFunnyThingIWant(IClown clownType) { clownType.Honk(); }
public Circus(IClown clown, IElephant elephant, string location) { Clown = clown; Elephant = elephant; Location = location; }
private static void DoJob(IClown man) { Console.WriteLine(man.FunnyThingIHave); man.Honk(); }