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


C# StandardKernel.GetAll方法代码示例

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


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

示例1: CanBeBoundToNormalBaseType

        public void CanBeBoundToNormalBaseType()
        {
            using (IKernel kernel = new StandardKernel())
            {
                kernel.Bind(
                    x => x.FromThisAssembly()
                          .SelectAllClasses().InNamespaceOf<ClassWithManyInterfaces>()
                          .BindSelection((ts, ti) => ti.Where(i => !i.IsInterface)));
                var instances = kernel.GetAll<object>();

                instances.Select(i => i.GetType()).Should().BeEquivalentTo(typeof(DefaultConvention), typeof(ClassWithManyInterfaces));
            }
        }
开发者ID:ryepup,项目名称:ninject.extensions.conventions,代码行数:13,代码来源:NormalClassBindingTests.cs

示例2: CanBeBoundToOpenGenericInterfaceOfPartiallyClosedBaseClass

        public void CanBeBoundToOpenGenericInterfaceOfPartiallyClosedBaseClass()
        {
            using (IKernel kernel = new StandardKernel())
            {
                kernel.Bind(
                    x => x.FromThisAssembly()
                          .SelectAllClasses().InNamespaceOf(typeof(OpenGenericClassWithManyInterfaces<>))
                          .BindAllInterfaces());
                var instances = kernel.GetAll<IBaseOpenGenericInterface1<double>>();

                instances.Select(i => i.GetType()).Should().BeEquivalentTo(
                    typeof(OpenGenericClassWithManyInterfaces<double>),
                    typeof(GenericBaseClassWithManyInterfaces<double>));
            }
        }
开发者ID:EstevaoLuis,项目名称:ninject.extensions.conventions,代码行数:15,代码来源:OpenGenericClassBindingTests.cs

示例3: BuildMediator

        private static IMediator BuildMediator()
        {
            var kernel = new StandardKernel();
            kernel.Components.Add<IBindingResolver, ContravariantBindingResolver>();
            kernel.Bind(scan => scan.FromAssemblyContaining<IMediator>().SelectAllClasses().BindDefaultInterface());
            kernel.Bind(scan => scan.FromAssemblyContaining<Ping>().SelectAllClasses().BindAllInterfaces());
            kernel.Bind<TextWriter>().ToConstant(Console.Out);

            var serviceLocator = new NinjectServiceLocator(kernel);
            var serviceLocatorProvider = new ServiceLocatorProvider(() => serviceLocator);
            kernel.Bind<ServiceLocatorProvider>().ToConstant(serviceLocatorProvider);

            var handlers = kernel.GetAll<INotificationHandler<Pinged>>();

            var mediator = serviceLocator.GetInstance<IMediator>();

            return mediator;
        }
开发者ID:BredStik,项目名称:MediatR,代码行数:18,代码来源:Program.cs

示例4: MultipleAssembliesCanBeUsed

        public void MultipleAssembliesCanBeUsed()
        {
            using (IKernel kernel = new StandardKernel())
            {
                kernel.Bind(
                    x => x.From("TestPlugin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")
                          .SelectAllTypes()
                          .Join.FromThisAssembly().SelectAllClasses()
                          .BindDefaultInterface());
                var instances = kernel.GetAll<IDefaultConvention>();

                instances.Count().Should().Be(2);
            }
        }
开发者ID:regisbsb,项目名称:Ninject.Extensions.Conventions,代码行数:14,代码来源:AssemblyLoadingTests.cs

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