Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Ninject;
- using Ninject.Activation;
- using Ninject.Extensions.Factory;
- using Ninject.Planning.Targets;
- using System;
- using System.Linq;
- namespace DI
- {
- public interface INumberFactory
- {
- Test Create(int a);
- }
- public class Test
- {
- public Test(int a) { }
- }
- class Program
- {
- static void Main(string[] args)
- {
- var kernel = new StandardKernel(new FuncModule());
- kernel.Bind<Test>().ToSelf().WithConstructorArgument("a" , (context, target) =>
- {
- Console.WriteLine("I'm trying to retrieve the constructor argument");
- return 0;
- });
- kernel.Bind<INumberFactory>().ToFactory();
- // Nothing is printed, even if it logically should be
- kernel.Get<INumberFactory>().Create(1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement