当前位置: 首页>>代码示例>>C#>>正文


C# StandardKernel.Rebind方法代码示例

本文整理汇总了C#中StandardKernel.Rebind方法的典型用法代码示例。如果您正苦于以下问题:C# StandardKernel.Rebind方法的具体用法?C# StandardKernel.Rebind怎么用?C# StandardKernel.Rebind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StandardKernel的用法示例。


在下文中一共展示了StandardKernel.Rebind方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            var kerner = new StandardKernel();
            //kerner.Bind<ICreditCard>().To<MasterCard>();
            kerner.Bind<ICreditCard>().To<Visa>();
            kerner.Rebind<ICreditCard>().To<MasterCard>();

            var shopper = kerner.Get<Shopper>();

            Console.WriteLine(shopper.Charge());
            Console.Read();
        }
开发者ID:Qanai,项目名称:NinjectIoc,代码行数:12,代码来源:Program.cs

示例2: BuiltinCompile

        /// <summary>
        /// Compiles the built-in embedded resources.
        /// </summary>
        private static void BuiltinCompile()
        {
            // Create kernel.
            var kernel = new StandardKernel();
            kernel.Load<ProtogameAssetIoCModule>();
            kernel.Load<ProtogameScriptIoCModule>();
            var services = new GameServiceContainer();
            var assetContentManager = new AssetContentManager(services);
            kernel.Bind<IAssetContentManager>().ToMethod(x => assetContentManager);
            kernel.Bind<IRenderBatcher>().To<NullRenderBatcher>();

            // Only allow source and raw load strategies.
            kernel.Unbind<ILoadStrategy>();
            kernel.Bind<ILoadStrategy>().To<LocalSourceLoadStrategy>();
            var assetModule = new ProtogameAssetIoCModule();
            assetModule.LoadRawAssetStrategies(kernel);

            // Set up remaining bindings.
            kernel.Bind<IAssetCleanup>().To<DefaultAssetCleanup>();
            kernel.Bind<IAssetOutOfDateCalculator>().To<DefaultAssetOutOfDateCalculator>();
            kernel.Bind<IAssetCompilationEngine>().To<DefaultAssetCompilationEngine>();

            // Rebind for builtin compilation.
            kernel.Rebind<IRawAssetLoader>().To<BuiltinRawAssetLoader>();

            // Set up the compiled asset saver.
            var compiledAssetSaver = new CompiledAssetSaver();

            // Retrieve the asset manager.
            var assetManager = kernel.Get<LocalAssetManager>();
            assetManager.AllowSourceOnly = true;
            assetManager.SkipCompilation = true;

            // Retrieve the transparent asset compiler.
            var assetCompiler = kernel.Get<ITransparentAssetCompiler>();

            // Retrieve all of the asset savers.
            var savers = kernel.GetAll<IAssetSaver>();

            var rawLoader = kernel.Get<IRawAssetLoader>();

            // For each of the platforms, perform the compilation of assets.
            foreach (var platformName in new[]
                {
                    "Android",
                    "iOS",
                    "Linux",
                    "MacOSX",
                    "Ouya",
                    "Windows",
                })
            {
                Console.WriteLine("Starting compilation for " + platformName);
                var platform = (TargetPlatform)Enum.Parse(typeof(TargetPlatform), platformName);
                var outputPath = Environment.CurrentDirectory;
                assetManager.RescanAssets();

                // Create the output directory if it doesn't exist.
                if (!Directory.Exists(outputPath))
                {
                    Directory.CreateDirectory(outputPath);
                }

                // Get a list of asset names that we need to recompile for this platform.
                var assetNames = rawLoader.ScanRawAssets();

                foreach (var asset in assetNames.Select(assetManager.GetUnresolved))
                {
                    Console.Write("Compiling " + asset.Name + " for " + platform + "... ");
                    try
                    {
                        assetCompiler.HandlePlatform(asset, platform, true);

                        foreach (var saver in savers)
                        {
                            var canSave = false;
                            try
                            {
                                canSave = saver.CanHandle(asset);
                            }
                            catch (Exception)
                            {
                            }

                            if (canSave)
                            {
                                try
                                {
                                    var result = saver.Handle(asset, AssetTarget.CompiledFile);
                                    compiledAssetSaver.SaveCompiledAsset(
                                        outputPath,
                                        asset.Name,
                                        result,
                                        result is CompiledAsset,
                                        platformName);
                                    Console.WriteLine("done.");
                                    break;
//.........这里部分代码省略.........
开发者ID:RedpointGames,项目名称:Protogame,代码行数:101,代码来源:Program.cs


注:本文中的StandardKernel.Rebind方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。