Skip to content

Instantly share code, notes, and snippets.

@akimboyko

akimboyko/gist:4370128

Last active Dec 10, 2015
Embed
What would you like to do?
Ninject Abstract Factory sample
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