Skip to content

Instantly share code, notes, and snippets.

@JeffryGonzalez
Last active January 7, 2016 10:35
Show Gist options
  • Select an option

  • Save JeffryGonzalez/afe27d2c1ced6120c40d to your computer and use it in GitHub Desktop.

Select an option

Save JeffryGonzalez/afe27d2c1ced6120c40d to your computer and use it in GitHub Desktop.
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