Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Main()
- {
- using(var kernel = new StandardKernel(new ExampleKernel()))
- {
- var d6 = kernel.Get<Die>();
- var d20 = kernel.Get<Die>(new ConstructorArgument("numSides", 20));
- d6.NumSides.Dump();
- d20.NumSides.Dump();
- }
- }
- public interface IRandomProvider
- {
- int GetRandom(int lower, int upper);
- }
- public class RandomProvider : IRandomProvider
- {
- private Random _random = new Random();
- public int GetRandom(int lower, int upper)
- {
- return lower + _random.Next(upper - lower);
- }
- }
- public class Die
- {
- public int NumSides { get; private set; }
- public IRandomProvider Provider { get; private set; }
- public Die(int numSides, IRandomProvider provider)
- {
- NumSides = numSides;
- Provider = provider;
- }
- }
- public class ExampleKernel : NinjectModule
- {
- public override void Load()
- {
- Bind<IRandomProvider>()
- .To<RandomProvider>();
- Bind<Die>()
- .ToSelf()
- .WithConstructorArgument("numSides", 6);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement