Last active
January 7, 2016 10:35
-
-
Save JeffryGonzalez/afe27d2c1ced6120c40d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Text; | |
| using System.Threading.Tasks; | |
| using Microsoft.Practices.Unity; | |
| namespace DiWithUnity | |
| { | |
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| var container = new UnityContainer(); | |
| container.RegisterType<Periodical<SomeState>, Book<SomeState>>(); | |
| var thing = container.Resolve<Periodical<SomeState>>(); | |
| Console.WriteLine(thing.DoSomething()); | |
| Console.WriteLine(thing.ConcreteMessage()); | |
| } | |
| } | |
| public abstract class Periodical<T> where T : new() | |
| { | |
| private T GenericInner; | |
| protected Periodical() | |
| { | |
| GenericInner = new T(); | |
| } | |
| public string ConcreteMessage() | |
| { | |
| return "Base handled this " + GenericInner.ToString(); | |
| } | |
| public abstract string DoSomething(); | |
| } | |
| public class Book<T> : Periodical<T> where T: new() | |
| { | |
| public Book():base() | |
| { | |
| } | |
| public override string DoSomething() | |
| { | |
| return "From the Concrete Class"; | |
| } | |
| } | |
| public class SomeState | |
| { | |
| public override string ToString() | |
| { | |
| return "This is from the type parameter"; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment