Last active
December 10, 2015 02:48
-
-
Save akimboyko/4370128 to your computer and use it in GitHub Desktop.
Ninject Abstract Factory sample
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
void Main() | |
{ | |
var kernel = new StandardKernel(); | |
kernel.Load<FuncModule>(); // for sake of LinqPAD | |
kernel.Bind<IJobFactory>().ToFactory(); | |
// wire concreet implementation of | |
kernel | |
.Bind<IJob>() | |
.To<JobImpl1>() | |
.NamedLikeFactoryMethod((IJobFactory f) => f.GetJob()); | |
var abstractFactory = kernel.Get<IJobFactory>(); | |
abstractFactory.GetJob().Dump(); | |
} | |
public abstract class IJob { } | |
public class JobImpl1 : IJob { } | |
public class JobImpl2 : IJob { } | |
public interface IJobFactory | |
{ | |
IJob GetJob(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment