当前位置: 首页>>代码示例>>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;未经允许,请勿转载。