當前位置: 首頁>>代碼示例>>C#>>正文


C# StandardKernel.Rebind方法代碼示例

本文整理匯總了C#中Ninject.StandardKernel.Rebind方法的典型用法代碼示例。如果您正苦於以下問題:C# StandardKernel.Rebind方法的具體用法?C# StandardKernel.Rebind怎麽用?C# StandardKernel.Rebind使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Ninject.StandardKernel的用法示例。


在下文中一共展示了StandardKernel.Rebind方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: InstallAndRemovePackagesTest

        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);
            }
        }
開發者ID:burzyk,項目名稱:Artemida,代碼行數:27,代碼來源:ClientManagerTests.cs

示例2: CreateContainer

        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;
        }
開發者ID:davidwhitney,項目名稱:FourthWall,代碼行數:29,代碼來源:ContainerBuilder.cs

示例3: BuildDefaultKernelForTests

        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;
        }
開發者ID:prescottadam,項目名稱:pMixins,代碼行數:25,代碼來源:KernelFactory.cs

示例4: RegisterDependencies

 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));
 }
開發者ID:coolcode,項目名稱:app,代碼行數:9,代碼來源:Global.asax.cs

示例5: CanReplaceBinding

 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>());
 }
開發者ID:abalkany,項目名稱:Ninject-Examples,代碼行數:7,代碼來源:Chapter_01_Kernel_Registration.cs

示例6: GetTestService

 protected CodeCampService GetTestService()
 {
     var kernel = new StandardKernel();
     Bootstrapper.Configure(kernel);
     kernel.Rebind<CCDB>().ToConstant(dbContext);
     return kernel.Get<CodeCampService>();
 }
開發者ID:cfranciscodev,項目名稱:WebSite,代碼行數:7,代碼來源:TestRepositoryBase.cs

示例7: CreateKernel

 protected override IKernel CreateKernel()
 {
     var kernel = new StandardKernel();
     kernel.Load(Assembly.GetExecutingAssembly());
     kernel.Rebind<CoffeeRequestRepository>().ToConstant(new CoffeeRequestRepository()).InSingletonScope();
     return kernel;
 }
開發者ID:brunosantos,項目名稱:CoffeeRun2,代碼行數:7,代碼來源:Global.asax.cs

示例8: Main

        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();
        }
開發者ID:KHProjects,項目名稱:KH-Parker-Fox,代碼行數:30,代碼來源:Program.cs

示例9: AwardScholarship

        /// <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");
        }
開發者ID:calmajos,項目名稱:enterprise-web-app-136,代碼行數:38,代碼來源:AwardClient.cs

示例10: Configure

        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();
        }
開發者ID:pragmasolutions,項目名稱:Alejandria,代碼行數:28,代碼來源:IoCConfig.cs

示例11: IntegrationTestBase

        // 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();
        }
開發者ID:robrich,項目名稱:BetaSigmaPhi,代碼行數:30,代碼來源:IntegrationTestBase.cs

示例12: Main

        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>();
        }
開發者ID:jasongdove,項目名稱:wwhomper,代碼行數:8,代碼來源:Program.cs

示例13: Configure

        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;
            //      });
        }
開發者ID:silviaeaguilar,項目名稱:SistemaGestion,代碼行數:58,代碼來源:IoCConfig.cs

示例14: CreateKernel

        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;
        }
開發者ID:shoftee,項目名稱:OpenStory,代碼行數:9,代碼來源:Program.cs

示例15: ComparerToCheckIfObjectsShouldBeTheSameShouldBePluggable

        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>());
        }
開發者ID:sportingsolutions,項目名稱:ObjectDiffer,代碼行數:10,代碼來源:IoCTests.cs


注:本文中的Ninject.StandardKernel.Rebind方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。