Example #1
0
        public void InstallAndRemovePackagesTest()
        {
            using (var kernel = new StandardKernel(new DefaultBindingsModule()))
            {
                kernel.Rebind<ILog>().To<NullLog>().InSingletonScope();
                kernel.Rebind<IClientConfiguration>()
                    .ToMethod(x => new MockConfiguration(new[] { "Artemida.Tests.TestPackage.Core", "Artemida.Tests.TestPackage.FeatureA", "Artemida.Tests.TestPackage.FeatureB" }))
                    .InSingletonScope();

                var packagesManager = kernel.Get<IPackagesManager>();
                var manager = kernel.Get<IClientManager>();

                var packages = packagesManager.GetInstalledPackages();
                Assert.AreEqual(0, packages.Count);
                manager.RefreshPackages();

                packages = packagesManager.GetInstalledPackages();
                Assert.AreEqual(3, packages.Count);

                var config = (MockConfiguration)kernel.Get<IClientConfiguration>();
                config.SetPackages(new[] { "Artemida.Tests.TestPackage.Core", "Artemida.Tests.TestPackage.FeatureA" });

                manager.RefreshPackages();
                packages = packagesManager.GetInstalledPackages();
                Assert.AreEqual(2, packages.Count);
            }
        }
        public static IKernel CreateContainer()
        {
            var container = new StandardKernel();
            container.Bind(x => x.FromAssemblyContaining<Startup>().SelectAllClasses().BindToSelf());
            container.Bind(x => x.FromAssemblyContaining<IFileSystem>().SelectAllClasses().BindAllInterfaces());

            container.Bind(x =>
            {
                x.FromAssemblyContaining<Startup>()
                    .SelectAllClasses()
                    .Excluding<CachingMediaSource>()
                    .BindAllInterfaces();
            });

            container.Rebind<MediaSourceList>()
                .ToMethod(x =>
                {
                    var mediaSources = x.Kernel.GetAll<IMediaSource>();
                    var sources = new MediaSourceList();
                    sources.AddRange(mediaSources.Select(s => x.Kernel.Get<CachingMediaSource>().WithSource(s)));
                    return sources;
                });

            container.Rebind<ServerConfiguration>()
                .ToMethod(x => x.Kernel.Get<ServerConfigurationLoader>().GetConfiguration())
                .InSingletonScope();

            return container;
        }
Example #3
0
        public static IKernel BuildDefaultKernelForTests(bool copyToServiceLocator = true)
        {
            var Kernel =
                new StandardKernel(
                    new StandardModule(),
                    new pMixinsStandardModule());

            Kernel.Rebind<IVisualStudioEventProxy>().To<TestVisualStudioEventProxy>().InSingletonScope();
            Kernel.Rebind<IVisualStudioWriter>().To<TestVisualStudioWriter>();
            Kernel.Rebind<IMicrosoftBuildProjectAssemblyReferenceResolver>()
                .To<TestMicrosoftBuildProjectAssemblyReferenceResolver>().InSingletonScope();
            Kernel.Rebind<ITaskFactory>().To<TestTaskFactoryWrapper>();

            Kernel.Bind<ICodeBehindFileHelper>().To<DummyCodeBehindFileHelper>();

            if (copyToServiceLocator)
                ServiceLocator.Kernel = Kernel;

            LoggingActivity.Initialize(Kernel.Get<IVisualStudioWriter>());

            //Make sure the VisualStudioOpenDocumentManager loads early
            Kernel.Get<IVisualStudioOpenDocumentManager>();

            return Kernel;
        }
Example #4
0
 private static void RegisterDependencies()
 {
     IKernel kernel = new StandardKernel(new DefaultModule());
     kernel.Rebind<DbContext>().To<LinkknilContext>().InTransientScope();
     kernel.Rebind<IEntityWatcher>().To<CustomEntityWatcher>();
     kernel.Bind<IFileService>().To<AliyunFileService>();
     //kernel.Rebind<IFileService>().To<WebFileService>();
     DependencyResolver.SetResolver(new NInjectDependencyResolver(kernel));
 }
 public void CanReplaceBinding()
 {
     var kernel = new StandardKernel();
     kernel.Bind<IVegetable>().To<Carrot>();
     kernel.Rebind<IVegetable>().To<GreenBean>();
     Assert.That(kernel.Get<IVegetable>(), Is.InstanceOf<GreenBean>());
 }
 protected CodeCampService GetTestService()
 {
     var kernel = new StandardKernel();
     Bootstrapper.Configure(kernel);
     kernel.Rebind<CCDB>().ToConstant(dbContext);
     return kernel.Get<CodeCampService>();
 }
Example #7
0
 protected override IKernel CreateKernel()
 {
     var kernel = new StandardKernel();
     kernel.Load(Assembly.GetExecutingAssembly());
     kernel.Rebind<CoffeeRequestRepository>().ToConstant(new CoffeeRequestRepository()).InSingletonScope();
     return kernel;
 }
Example #8
0
        static void Main(string[] args)
        {
            //container is called kernal (because it represents the kernal / core of the application

              //var kernal = new StandardKernel();
              //kernal.Bind<ICreditCard>().To<MasterCard>();

              var kernal = new StandardKernel(new MyModule());
              //kernal.Rebind<ICreditCard>().To<MasterCard>();

              //dont have to register all the types.. ninject will automatically register concrete types so we can ask for any concrete type and ninject will know how to create it.. without us having to speciy it specificallly in the container.. makes it a little easier so we don't have to configure every single class that we are going to use.
              //(dont need to register shopper type because its automatic)
              //whenever we ask for an ICreditCard were going to get back a MasterCard.

              var shopper = kernal.Get<Shopper>();
              shopper.Charge();
              Console.WriteLine(shopper.ChargesForCurrentCard);

              kernal.Rebind<ICreditCard>().To<MasterCard>();

              var shopper2 = kernal.Get<Shopper>();
              shopper2.Charge();
              Console.WriteLine(shopper2.ChargesForCurrentCard);

              //Shopper shopper3 = new Shopper();
              //shopper3.Charge();
              //Console.WriteLine(shopper3.ChargesForCurrentCard);

              Console.Read();
        }
        /// <summary>
        /// Award scholarship
        /// </summary>
        public void AwardScholarship()
        {
            // Wrote the resolver myself
            var resolver = new Resolver();

            var rankBy1 = resolver.ChooseRanking("undergrad");
            var award1 = new Award(rankBy1);

            award1.AwardScholarship("100");

            var rankBy2 = resolver.ChooseRanking("grad");
            var award2 = new Award(rankBy2);
            award2.AwardScholarship("200");

            // using Ninject instead of the custom resolver I wrote.
            var kernelContainer = new StandardKernel();
            kernelContainer.Bind<IRanking>().To<RankByGPA>();
            var award3 = kernelContainer.Get<Award>();
            award3.AwardScholarship("101");

            kernelContainer.Rebind<IRanking>().To<RankByInnovation>();
            var award4 = kernelContainer.Get<Award>();
            award4.AwardScholarship("201");

            // using Unity instead of custom resolver.
            var unityContainer = new UnityContainer();
            unityContainer.RegisterType<IRanking, RankByGPA>();
            var award5 = unityContainer.Resolve<Award>();
            award5.AwardScholarship("102");

            unityContainer = new UnityContainer();
            unityContainer.RegisterType<IRanking, RankByInnovation>();
            var award6 = unityContainer.Resolve<Award>();
            award6.AwardScholarship("202");
        }
Example #10
0
        public static void Configure(StandardKernel kernel)
        {
            kernel.Bind(x => x.FromAssembliesMatching("Alejandria.*")
                                 .SelectAllClasses()
                                 .BindAllInterfaces()
                                 .Configure(c => c.InTransientScope()));

            kernel.Bind(x => x.FromAssembliesMatching("Framework.*")
                                 .SelectAllClasses()
                                 .BindAllInterfaces()
                                 .Configure(c => c.InTransientScope()));

            kernel.Bind(x => x.FromAssembliesMatching("Alejandria.*")
                                 .SelectAllInterfaces()
                                 .EndingWith("Factory")
                                 .BindToFactory()
                                 .Configure(c => c.InSingletonScope()));

            kernel.Bind(x => x.FromThisAssembly()
                                 .SelectAllInterfaces()
                                 .Including<IRunAfterLogin>()
                                 .BindAllInterfaces()
                                 .Configure(c => c.InSingletonScope()));

            kernel.Bind<IIocContainer>().To<NinjectIocContainer>().InSingletonScope();
            kernel.Rebind<IClock>().To<Clock>().InSingletonScope();
            //kernel.Bind<IMessageBoxDisplayService>().To<MessageBoxDisplayService>().InSingletonScope();
        }
Example #11
0
        public void DoIt()
        {
            using (var kernel = new Ninject.StandardKernel())
            {
                kernel.Load <Nailhang.Mongodb.Module>();
                kernel.Rebind <Nailhang.Mongodb.MongoConnection>()
                .ToConstant(new MongoConnection
                {
                    ConnectionString = "mongodb://192.168.0.32",
                    DbName           = "nail_tests"
                });


                var ms = kernel.Get <IModulesStorage>();
                ms.StoreModule(new IndexBase.Module
                {
                    Assembly              = "lala",
                    Description           = "big lala",
                    FullName              = "very big lala",
                    InterfaceDependencies = new IndexBase.TypeReference[] { },
                    Interfaces            = new IndexBase.ModuleInterface[] { },
                    ModuleBinds           = new IndexBase.TypeReference[] { },
                    ObjectDependencies    = new IndexBase.TypeReference[] { },
                    Objects      = new IndexBase.ModuleObject[] { },
                    Significance = Significance.High
                });

                Assert.IsNotEmpty(ms.GetModules().ToArray());
                ms.DropModules("NOTREALNAMESPACE");
                Assert.IsNotEmpty(ms.GetModules().ToArray());
                ms.DropModules("");
                Assert.IsEmpty(ms.GetModules().ToArray());
            }
        }
        // Technically we should probably reset this on each test, but we'll always get the same answer and it takes a while to do so ...
        // [TestCaseSource] runs before [TestFixtureSetUp] and we need this before even that
        // FRAGILE: Duplicate of Web/App_Start/NinjectWebCommon.cs
        public IntegrationTestBase()
        {
            // Kick off Ninject
            IKernel kernel = new StandardKernel();

            string path = new Uri(Path.GetDirectoryName(typeof(IntegrationTestBase).Assembly.CodeBase) ?? "").LocalPath;
            string thisNamespace = typeof(IntegrationTestBase).FullName.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries)[0]; // FRAGILE: ASSUME: All our code is in this namespace

            kernel.Bind(x => x
                .FromAssembliesInPath(path) // Blows with "not marked as serializable": , a => a.FullName.StartsWith( assemblyPrefix ) )
                .Select(type => type.IsClass && !type.IsAbstract && type.FullName.StartsWith(thisNamespace)) // .SelectAllClasses() wires up everyone else's stuff too
                .BindDefaultInterface()
            );

            // Add other bindings as necessary
            kernel.Rebind<IBetaSigmaPhiContext>().ToMethod(_ => (IBetaSigmaPhiContext)kernel.GetService(typeof(BetaSigmaPhiContext)));
            this.InitializeOtherTypes(kernel);

            // Initialize the service locator
            ServiceLocator.Initialize(kernel.GetService);

            // Use ServiceLocator sparingly to start us off
            this.SqlHelper = ServiceLocator.GetService<ISqlHelper>();

            // Start a transaction so we won't persist data changes made during tests
            this.transaction = new TransactionScope();
        }
Example #13
0
        public static void Main(string[] args)
        {
            var kernel = new StandardKernel(new sharperbot.Module(), new wwhomper.Module());

            kernel.Rebind<ITrashGearStrategy>().To<BasicTrashGearStrategy>();

            var p = kernel.Get<Program>();
        }
        public static void Configure(StandardKernel kernel)
        {
            kernel.Bind(x => x.FromAssembliesMatching("GestionAdministrativa.*")
                                 .SelectAllClasses()
                                 .BindAllInterfaces()
                                 .Configure(c => c.InTransientScope()));

            kernel.Bind(x => x.FromAssembliesMatching("Framework.*")
                                 .SelectAllClasses()
                                 .BindAllInterfaces()
                                 .Configure(c => c.InTransientScope()));

            kernel.Bind(x => x.FromAssembliesMatching("GestionAdministrativa.*")
                                 .SelectAllInterfaces()
                                 .EndingWith("Factory")
                                 .BindToFactory()
                                 .Configure(c => c.InSingletonScope()));

            kernel.Bind(x => x.FromThisAssembly()
                                 .SelectAllInterfaces()
                                 .Including<IRunAfterLogin>()
                                 .BindAllInterfaces()
                                 .Configure(c => c.InSingletonScope()));

            kernel.Bind<IIocContainer>().To<NinjectIocContainer>().InSingletonScope();
            kernel.Rebind<IClock>().To<Clock>().InSingletonScope();
               // kernel.Bind<IMessageBoxDisplayService>().To<MessageBoxDisplayService>().InSingletonScope();

            //Custom Factories
            //kernel.Rebind<ICajaMovientoFactory>().To<CajaMovimientoFactory>();

            //Overide defaults bindings.
            kernel.Unbind<IGestionAdministrativaContext>();
            kernel.Bind<IGestionAdministrativaContext>().To<GestionAdministrativaContext>().InSingletonScope();

            kernel.Unbind<IFormRegistry>();
            kernel.Bind<IFormRegistry>().To<FormRegistry>().InSingletonScope();

            kernel.Unbind<IEncryptionService>();
            kernel.Bind<IEncryptionService>().To<EncryptionService>().InSingletonScope();

            //kernel.Bind<IRepository<TituloStockMigracion>>().To<EFRepository<TituloStockMigracion>>()
            //      .WithConstructorArgument("dbContext", (p) =>
            //      {
            //          var dbContext = new MigracionLaPazEntities();

            //          // Do NOT enable proxied entities, else serialization fails
            //          dbContext.Configuration.ProxyCreationEnabled = false;

            //          // Load navigation properties explicitly (avoid serialization trouble)
            //          dbContext.Configuration.LazyLoadingEnabled = false;

            //          // Because Web API will perform validation, we don't need/want EF to do so
            //          dbContext.Configuration.ValidateOnSaveEnabled = false;

            //          return dbContext;
            //      });
        }
Example #15
0
        private static IKernel CreateKernel()
        {
            var kernel = new StandardKernel(new ServerModule(), new AuthServerModule(), new WcfServiceModule());

            kernel.Rebind<NexusConnectionInfo>().ToConstant(GetNexusConnectionInfo());
            kernel.Bind<OsWcfConfiguration>().ToConstant(GetWcfConfiguration());

            return kernel;
        }
        public void ComparerToCheckIfObjectsShouldBeTheSameShouldBePluggable()
        {
            var comparer = Substitute.For<IEqualityComparer<object>>();
            var kernel = new StandardKernel(new ObjectDifferModule());
            kernel.Rebind<IEqualityComparer<object>>().ToConstant(comparer).Named("SameObjectComparer");
            var differ = kernel.Get<IDiffer>();

            var a = differ.Diff(new List<int> { 1, 2, 3 }, new List<int> { 2, 3, 4 });
            comparer.Received().Equals(Arg.Any<object>(), Arg.Any<object>());
        }
Example #17
0
        public static IKernel CreatePublicKernel()
        {
            var kernel = new StandardKernel();
            kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel);
            kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();

            RegisterServices(kernel);
            kernel.Rebind<IdbContextProvider>().To<dbContextProviderWithoutSingletonPerRequest>();
            return kernel;
        }
Example #18
0
 public static CodeCampService GetTestService(OCCDB dbContext, Action<IKernel> bindingDelegate = null)
 {
     var kernel = new StandardKernel();
     Bootstrapper.Configure(kernel);
     kernel.Rebind<OCCDB>().ToConstant(dbContext);
     if (bindingDelegate != null)
     {
         bindingDelegate.Invoke(kernel);
     }
     return kernel.Get<CodeCampService>();
 }
Example #19
0
 public static CodeCampService GetTestService(CCDB dbContext, Action<IKernel> bindingDelegate = null)
 {
     var kernel = new StandardKernel();
     Bootstrapper.Configure(kernel);
     kernel.Rebind<CCDB>().ToConstant(dbContext);
     if (bindingDelegate != null)
     {
         bindingDelegate.Invoke(kernel);
     }
     //return kernel.Get<CodeCampService>();
     return new CodeCampService(kernel.Get<PersonRepository>(),
         kernel.Get<SessionRepository>(),
         kernel.Get<MetadataRepository>(),
         kernel.Get<TaskRepository>(),
         kernel.Get<TagRepository>());
 }
        public void SetUp()
        {
            kernel = new StandardKernel();
            Kernel.RegisterCoreBindings(kernel);
            kernel.Bind<IFileSystemDirectory>().ToConstant(new TestFileSystemDirectory("root")).WhenTargetHas
                <SuiteRootAttribute>();
            kernel.Bind<IFileSystemDirectory>().ToConstant(new TestFileSystemDirectory("target")).WhenTargetHas<TargetRootAttribute>();
            kernel.Bind<IFileSystemDirectory>().ToConstant(new TestFileSystemDirectory("cache")).WhenTargetHas<CacheRootAttribute>();
            kernel.Bind<IUserOutput>().To<TestUserOutput>();

            parameters = new Mock<IParameters>();
            parameters.SetupGet(p => p.Goal).Returns("debug");
            kernel.Bind<IParameters>().ToConstant(parameters.Object);
            TestSetup.EnsureFactoryExtensionLoaded(kernel);

            kernel.Rebind<ISuiteFactory>().To<DefaultSuiteFactory>().InTransientScope();
        }
Example #21
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            IKernel kernel = new StandardKernel();
            // Repos
            kernel.Bind<IClientRepository>().To<InMemoryClientRepository>();
            kernel.Bind<ITokenRepository>().To<InMemoryTokenRepository>();

            // Services
            kernel.Bind<IClientService>().To<ClientService>();
            kernel.Bind<ITokenService>().To<TokenService>();
            kernel.Bind<IResourceOwnerService>().To<ResourceOwnerService>();
            kernel.Bind<IAuthorizationGrantService>().To<AuthorizationGrantService>();
            kernel.Bind<IServiceFactory>().To<ServiceFactory>();

            // Providers
            kernel.Bind<IAuthorizationProvider>().To<AuthorizationProvider>();
            kernel.Bind<ITokenProvider>().To<TokenProvider>();
            kernel.Bind<IResourceProvider>().To<ResourceProvider>();

            
            // Token Endpoint Processors
            kernel.Bind<ContextProcessor<ITokenContext>>().To<AuthenticationCodeProcessor>();
            kernel.Bind<ContextProcessor<ITokenContext>>().To<ResourceOwnerPasswordCredentialProcessor>();
            kernel.Bind<ContextProcessor<ITokenContext>>().To<ClientCredentialsProcessor>();
            kernel.Bind<ContextProcessor<ITokenContext>>().To<RefreshTokenProcessor>();

            // Resource Endpoint Processors
            //TODO: Build Mac Processor
            kernel.Bind<ContextProcessor<IResourceContext>>().To<BearerProcessor>();

            // Authorization Endpoint Processors
            kernel.Rebind<ContextProcessor<IAuthorizationContext>>().To<AuthorizationCodeProcessor>();
            kernel.Bind<ContextProcessor<IAuthorizationContext>>().To<ImplicitFlowProcessor>();
    
            NinjectServiceLocator adapter = new NinjectServiceLocator(kernel);

            ServiceLocator.SetLocatorProvider(() => adapter);

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
        }
        public void ShouldBeAbleToResolveService()
        {
            Configuration.IProvider configurationProvider = A.Fake<Configuration.IProvider>();

            A.CallTo(() => configurationProvider.GetSettings()).Returns(
                new Configuration.Settings
                {
                    ElasticSearch = new Configuration.ElasticSearch(),
                    SparkCore = new Configuration.SparkCore()
                }
            );

            IKernel kernel = new StandardKernel(new Module(), new Io.Spark.Ninject.Module("TEST"));
            kernel.Rebind<Configuration.IProvider>().ToConstant(configurationProvider);

            IService service = kernel.Get<IService>();

            Assert.That(service, Is.Not.Null);
        }
        static void Main(string[] args)
        {
            IKernel kernel = new StandardKernel(new OrmConfigurationModule(), new HarnessModule());
            kernel.Rebind<ISampleSizeStep>().To<PlusOneSampleSizeStep>();
            var config = kernel.Get<IRunnerConfig>();

            List<ScenarioInRunResult> allRunResults = new List<ScenarioInRunResult>();

            for (int i = 0; i < config.NumberOfRuns; i++)
            {
                Console.WriteLine(String.Format("Starting run number {0} at {1}", i, DateTime.Now.ToShortTimeString()));
                allRunResults.AddRange(kernel.Get<ScenarioRunner>().Run(config.MaximumSampleSize, new CancellationToken())
                    .Select(r =>
                        new ScenarioInRunResult
                        {
                            ApplicationTime = r.ApplicationTime,
                            CommitTime = r.CommitTime,
                            ConfigurationName = r.ConfigurationName,
                            MemoryUsage = r.MemoryUsage,
                            SampleSize = r.SampleSize,
                            ScenarioName = r.ScenarioName,
                            SetupTime = r.SetupTime,
                            Status = r.Status,
                            Technology = r.Technology,
                            RunNumber = i + 1
                        }));
            }

            foreach (var formatter in kernel.GetAll<IResultFormatter<ScenarioInRunResult>>())
            {
                formatter.FormatResults(allRunResults);
            }


            Console.ReadLine();
        }
Example #24
0
        public IKernel CreateKernel(Uri serviceUrl, string realTimeServiceAddress)
        {
            StandardKernel kernel = null;

            try
            {
                kernel = new StandardKernel();

                kernel.Bind(x => x.FromAssembliesMatching("BuildingSecurity.*", "JohnsonControls.*")
                                        .SelectAllClasses()
                                        .Excluding<ReportingClient>()
                                        .Excluding<AlarmService>()
                                        .Excluding<MessageProcessingClient>()
                                        .Excluding<BuildingSecuritySessionStore>()
                                        .Excluding<BuildingSecurityClient>()
                                        .BindDefaultInterface()
                                        .Configure((b, c) => b.WithConstructorArgument("serviceUrl", serviceUrl))
                    );

#if IN_MEMORY_SETTINGS
                ReportServerConfiguration reportServer = new ReportServerConfiguration("http://10.10.93.183/ReportServer", "", "cwelchmi", "").CloneWithNewPassword("cwelchmi");
                var appSettings = new SettingsDictionary
                                                     {
                                                         {
                                                             ApplicationSettings.ReportServerConfiguration,
                                                             new DataSerializer<ReportServerConfiguration>().Serialize(
                                                                 reportServer)
                                                             }
                                                     };

                kernel.Bind<ITypedApplicationPreference>().ToMethod(x => new InMemoryApplicationSettings(appSettings, new Dictionary<string, SettingsDictionary>())).InSingletonScope();
#else
                kernel.Bind<ITypedApplicationPreference>().ToMethod(x => new CachingApplicationPreferences(new ApplicationPreferenceService(serviceUrl), new Cache(MemoryCache.Default, "ITypedApplicationPreference")));
#endif
                kernel.Bind<IBuildingSecuritySessionStore>().To<BuildingSecuritySessionStore>().InSingletonScope();

                kernel.Rebind<IBuildingSecurityClient>().To<BuildingSecurityClient>().InSingletonScope();
                kernel.Rebind<ISimulatorClient>().ToConstant<ISimulatorClient>(null);

                if (@"true".Equals(ConfigurationManager.AppSettings["UseSimulation"], StringComparison.InvariantCultureIgnoreCase))
                {
                    kernel.Rebind<IBuildingSecurityClient>().To<PseudoBuildingSecurityClient>().InSingletonScope();
                    kernel.Rebind<Scheduler>().To<Scheduler>().InSingletonScope();
                    kernel.Rebind<ISimulatorClient>().To<InMemorySimulationClient>().InSingletonScope();
                }

                kernel.Bind<ITypedSessionManagement>().ToMethod(x => new SessionManagementService(serviceUrl));
                kernel.Bind<ITypedAlarmService>().ToMethod(x => new AlarmService(serviceUrl, realTimeServiceAddress)).InSingletonScope();
                kernel.Bind<ITypedSystemInformationService>().ToMethod(x => new SystemInformationService(serviceUrl)).InSingletonScope();

                return kernel;
            }
            catch
            {
                if (kernel != null)
                {
                    kernel.Dispose();
                }

                throw;
            }
        }
 public RebindGenericToGeneric()
 {
     var kernel = new StandardKernel();
     kernel.Rebind<ICommon>().To<CommonImpl1>();
 }
 public RebindNonGenericToSelf()
 {
     var kernel = new StandardKernel();
     kernel.Rebind(typeof(CommonImpl1)).ToSelf();
 }
 public RebindGenericToNonGeneric()
 {
     var kernel = new StandardKernel();
     kernel.Rebind<ICommon>().To(typeof(CommonImpl1));
 }
Example #28
0
 public RebindGenericToSelf()
 {
     var kernel = new StandardKernel();
     kernel.Rebind<CommonImpl1>().ToSelf();
 }
 public RebindNonGenericToGeneric()
 {
     var kernel = new StandardKernel();
     kernel.Rebind(typeof(ICommon)).To<CommonImpl1>();
 }
Example #30
0
        public static void Configure(StandardKernel kernel)
        {
            IoCConfigBase.Configure(kernel);

            kernel.Rebind<IStateController>().To<StateController>().InSingletonScope();
        }
        public void RebindClearsAllBindingsForAType()
        {
            var kernel = new StandardKernel();
            kernel.Bind<IVegetable>().To<Carrot>();
            kernel.Bind<IVegetable>().To<GreenBean>();

            Assert.That(kernel.GetBindings(typeof(IVegetable)).Count(), Is.EqualTo(2));

            kernel.Rebind<IVegetable>().To<Peas>();

            Assert.That(kernel.GetBindings(typeof(IVegetable)).Count(), Is.EqualTo(1));
        }