Skip to content

Instantly share code, notes, and snippets.

@akimboyko
Last active December 10, 2015 02:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akimboyko/4370128 to your computer and use it in GitHub Desktop.
Save akimboyko/4370128 to your computer and use it in GitHub Desktop.
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