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


C# DependencyInjectionContainer.Resolve方法代码示例

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


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

示例1: Main

        public static void Main()
        {
            try
            {
                ThreadPoolConfiguration.Init();

                using (var container = new DependencyInjectionContainer())
                {
                    var gameApp = container.Resolve<GameApp>();
                    gameApp.Run();
                }
            }
            catch (Exception ex)
            {
                if (Debugger.IsAttached)
                {
                    Debugger.Break();
                }

                MessageBox.Show(ex.ToString(), "CubeHack", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
开发者ID:AndiAngerer,项目名称:cubehack,代码行数:22,代码来源:Program.cs

示例2: ConfigureDependencies

        public static void ConfigureDependencies(DependencyInjectionContainer container)
        {
            ILinqToAstoriaQueryEvaluationStrategy strategy;
            if (!container.TryResolve<ILinqToAstoriaQueryEvaluationStrategy>(out strategy))
            {
                container.Register<ILinqToAstoriaQueryEvaluationStrategy, LinqToAstoriaClrQueryEvaluationStrategy>();
                container.Register<IPrimitiveDataTypeResolver, NullPrimitiveDataTypeResolver>();
            }

            container.Register<IQueryDataSetBuilder, AstoriaQueryDataSetBuilder>();
            container.Register<IQueryRepositoryBuilder, AstoriaQueryRepositoryBuilderBase>();
            container.Register<IQueryExpressionEvaluator, LinqToAstoriaEvaluator>();
            container.Register<ILinqToAstoriaQueryResolver, LinqToAstoriaQueryResolver>();
            container.Register<ILinqToAstoriaQuerySpanGenerator, LinqToAstoriaQuerySpanGenerator>();
            container.Register<IClientQueryResultComparer, ClientQueryResultComparer>();
            container.Register<IOracleBasedDataSynchronizer, QueryDataSetSynchronizer>();
            container.Register<ILinqResultComparerContextAdapter, LinqResultComparerDataServiceContextAdapter>();
            container.Register<IQueryValueDeepCopyingVisitor, AstoriaQueryValueDeepCopyingVisitor>();
            container.Register<ISpatialClrTypeResolver, SpatialClrTypeResolver>();
            container.Register<ISpatialDataTypeDefinitionResolver, SpatialDataTypeDefinitionResolver>();

            container.RegisterCustomResolver(
                typeof(QueryRepository),
                resolver =>
                {
                    var workspace = container.Resolve<AstoriaWorkspace>();
                    if (workspace.CurrentQueryRepository == null)
                    {
                        var queryTypeLibrary = container.Resolve<QueryTypeLibrary>();
                        var queryRepositoryBuilder = container.Resolve<IQueryRepositoryBuilder>();
                        var queryRepository = queryRepositoryBuilder.CreateQueryRepository(workspace.ConceptualModel, queryTypeLibrary, workspace.DownloadedEntityContainerData);
                        workspace.CurrentQueryRepository = queryRepository;
                    }

                    return workspace.CurrentQueryRepository;
                });

            container.RegisterCustomResolver(
               typeof(IQueryDataSet),
               resolver =>
               {
                   var queryRepository = container.Resolve<QueryRepository>();
                   return queryRepository.DataSet;
               });

            container.RegisterServiceReference<IDataOracleService>(
               () =>
               {
                   var workspace = container.Resolve<AstoriaWorkspace>();
                   return workspace.OracleServiceUri;
               });

            container.RegisterCustomResolver(
                typeof(IEntitySetResolver),
                esResolver =>
                {
                    var workspace = container.Resolve<AstoriaWorkspace>();
                    return workspace.EntitySetResolver;
                });

            container.RegisterCustomResolver(
                typeof(IQueryTypeLibraryBuilder),
                queryTypeLibBuilderResolver =>
                {
                    var queryEvaluationStrategy = container.Resolve<ILinqToAstoriaQueryEvaluationStrategy>();
                    var primitiveTypeResolver = container.Resolve<IPrimitiveDataTypeResolver>();
                    var edmDataTypeResolver = container.Resolve<EdmDataTypeResolver>();
                    return new AstoriaQueryTypeLibraryBuilder(queryEvaluationStrategy, primitiveTypeResolver, edmDataTypeResolver);
                });

            container.RegisterCustomResolver(
                typeof(QueryTypeLibrary),
                queryTypeLib =>
                {
                    var workspace = container.Resolve<AstoriaWorkspace>();
                    if (workspace.CurrentQueryRepository == null)
                    {
                        var queryTypeLibraryBuilder = container.Resolve<IQueryTypeLibraryBuilder>();
                        var queryTypeLibrary = queryTypeLibraryBuilder.BuildLibraryWithoutClrTypeMapping(workspace.ConceptualModel);
                        queryTypeLibrary.UpdateClrTypeMapping(workspace.Assemblies.Select(ac => ac.Contents).ToArray());
                        return queryTypeLibrary;
                    }
                    else
                    {
                        return workspace.CurrentQueryRepository.TypeLibrary;
                    }
                });

            container.RegisterCustomResolver(
                typeof(IEntityModelConceptualDataServices),
                t =>
                {
                    var workspace = container.Resolve<AstoriaWorkspace>();

                    // Add data generation hints before creating structural data services
                    ResolveDataGenerationHints(workspace.ConceptualModel, container);

                    var builder = container.Resolve<IEntityModelConceptualDataServicesFactory>();
                    var services = builder.CreateConceptualDataServices(workspace.ConceptualModel);
                    ExceptionUtilities.CheckObjectNotNull(services, "Structural data services builder returned null unexpectedly");
//.........这里部分代码省略.........
开发者ID:larsenjo,项目名称:odata.net,代码行数:101,代码来源:AstoriaTestServices.cs

示例3: InitializeEntityModelStructuralDataServices

        private static void InitializeEntityModelStructuralDataServices(IEntityModelConceptualDataServices services, IEnumerable<EntityContainer> entityContainers, DependencyInjectionContainer container)
        {
            var driver = container.Resolve<IEntityContainerDataPopulationDriver>();
            driver.StructuralDataServices = services;
            driver.Random = container.Resolve<IRandomNumberGenerator>();
            driver.ThresholdForNumberOfEntities = -1;

            foreach (var entityContainer in entityContainers)
            {
                driver.EntityContainer = entityContainer;
                EntityContainerData data;
                driver.TryPopulateNextData(out data);
                driver.TryPopulateNextData(out data);
            }
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:15,代码来源:AstoriaTestServices.cs

示例4: ResolveDataGenerationHints

        private static void ResolveDataGenerationHints(EntityModelSchema model, DependencyInjectionContainer container)
        {
            var entityModelHintsResolver = container.Resolve<IEntityModelDataGenerationHintsResolver>();
            var primitiveResolver = container.Resolve<IPrimitiveDataTypeToDataGenerationHintsResolver>();

            entityModelHintsResolver.ResolveDataGenerationHints(model, primitiveResolver);
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:7,代码来源:AstoriaTestServices.cs

示例5: Start

        private async void Start()
        {
            using (Lock())
            {
                Save();

                await Task.Run(
                    () =>
                    {
                        try
                        {
                            using (var universe = new Universe(NullSaveFile.Instance, DataLoader.LoadMod(_modName)))
                            {
                                using (var container = new DependencyInjectionContainer())
                                {
                                    var gameLoop = container.Resolve<GameLoop>();
                                    var connectionManager = container.Resolve<GameConnectionManager>();
                                    gameLoop.Post(() => { var notAwaited = connectionManager.ConnectUniverseAsync(universe); });

                                    var gameApp = container.Resolve<GameApp>();
                                    gameApp.Run();
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            if (Debugger.IsAttached)
                            {
                                Debugger.Break();
                            }

                            MessageBox.Show(ex.ToString(), "CubeHack", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    });
            }
        }
开发者ID:AndiAngerer,项目名称:cubehack,代码行数:36,代码来源:ViewModel.cs

示例6: InitializeGlobalObjects

        /// <summary>
        /// Initializes the global objects.
        /// </summary>
        /// <param name="dependencyInjectionContainer">The dependency injection container.</param>
        public void InitializeGlobalObjects(DependencyInjectionContainer dependencyInjectionContainer)
        {
            ExceptionUtilities.CheckArgumentNotNull(dependencyInjectionContainer, "dependencyInjectionContainer");

            // pre-resolve global objects
            foreach (var globalObject in this.implementations.Where(c => c.IsGlobal))
            {
                var result = dependencyInjectionContainer.Resolve(globalObject.ContractType);
                IInitializable init = result as IInitializable;
                if (init != null)
                {
                    init.Initialize();
                }
            }
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:19,代码来源:DependencyInjectionConfigurator.cs

示例7: ConfigureDependenciesHelper

        /// <summary>
        /// The configuration of these dependencies will be called from other testcase hierarchies that do not inherit from this class.
        /// This method can be used in such hierarchies.
        /// </summary>
        /// <param name="container">container on which to register impelemntation dependencies</param>
        public static void ConfigureDependenciesHelper(DependencyInjectionContainer container)
        {
            container.Register<IClrTypeReferenceResolver, StronglyTypedClrTypeReferenceResolver>();
            container.Register<IObjectLayerCodeGenerator, StronglyTypedObjectLayerCodeGenerator>();
            container.Register<IQueryEvaluationStrategy, ClrQueryEvaluationStrategy>();
            container.Register<IModelGenerator, ODataV2ModelGenerator>();
            container.Register<IWorkspaceBuilder, ODataWorkspaceBuilder>(); // Is this also needed , since we register Custom Resolver below
            container.Register<IQueryRepositoryBuilder, AstoriaQueryRepositoryBuilderBase>();
            container.Register<IQueryDataSetBuilder, ODataQueryDataSetBuilder>();

            container.Register<IResourceLookup, AssemblyResourceLookup>();
            container.Register<IStringResourceVerifier, StringResourceVerifier>();
            container.Register<IQueryScalarValueToClrValueComparer, QueryScalarValueToClrValueComparer>();
            container.Register<IQueryExpressionEvaluator, LinqToAstoriaEvaluator>();
            container.Register<IClientCodeLayerGenerator, PocoClientCodeLayerGenerator>();

            container.Register<ILinqToAstoriaQueryEvaluationStrategy, LinqToAstoriaClrQueryEvaluationStrategy>();
            container.Register<IPrimitiveDataTypeResolver, NullPrimitiveDataTypeResolver>();
            container.Register<ILinqResultComparerContextAdapter, ODataObjectResultComparerContextAdapter>();

            container.Register<ISpatialClrTypeResolver, SpatialClrTypeResolver>();
            container.Register<ISpatialDataTypeDefinitionResolver, SpatialDataTypeDefinitionResolver>();
            container.Register<IPayloadTransformFactory, ODataLibPayloadTransformFactory>();

            container.RegisterCustomResolver(
                typeof(ODataTestWorkspace),
                t =>
                {
                    var builder = container.Resolve<ODataWorkspaceBuilder>();
                    var modelGenerator = container.Resolve<IModelGenerator>();
                    var workspace = builder.BuildWorkspace(modelGenerator.GenerateModel());
                    
                    return workspace;
                });

            container.RegisterCustomResolver(
                typeof(IQueryTypeLibraryBuilder),
                queryTypeLibBuilderResolver =>
                {
                    var queryEvaluationStrategy = container.Resolve<ILinqToAstoriaQueryEvaluationStrategy>();
                    var primitiveTypeResolver = container.Resolve<IPrimitiveDataTypeResolver>();
                    return new AstoriaQueryTypeLibraryBuilder(queryEvaluationStrategy, primitiveTypeResolver, new EdmDataTypeResolver());
                });

            // IQueryDataSet is built by the repository builder
            container.RegisterCustomResolver(
                typeof(IQueryDataSet),
                    t =>
                    {
                        var repository = container.Resolve<QueryRepository>();
                        return repository.DataSet;
                    });

            container.RegisterCustomResolver(
                typeof(QueryTypeLibrary),
                queryTypeLib =>
                {
                    var workspace = container.Resolve<ODataTestWorkspace>();
                    var queryTypeLibraryBuilder = container.Resolve<IQueryTypeLibraryBuilder>();
                    var queryTypeLibrary = queryTypeLibraryBuilder.BuildLibraryWithoutClrTypeMapping(workspace.ConceptualModel);
                    if (workspace.ObjectLayerAssembly != null)
                    {
                        queryTypeLibrary.UpdateClrTypeMapping(new[] { workspace.ObjectLayerAssembly });
                    }

                    return queryTypeLibrary;
                });

            container.RegisterCustomResolver(
                typeof(EntityContainerData),
                t =>
                {
                    // TODO: All Query tests fail when there is actual data, for now starting with empty data
                    var workspace = container.Resolve<ODataTestWorkspace>();
                    EntityContainerData data = null;
                    data = new EntityContainerData(workspace.ConceptualModel.GetDefaultEntityContainer());
                    
                    //var dataPopulationDriver = container.Resolve<EntityContainerDataPopulationDriver>();
                    //dataPopulationDriver.ThresholdForNumberOfEntities = -1;
                    //dataPopulationDriver.EntityContainer = workspace.ConceptualModel.GetDefaultEntityContainer();
                    //dataPopulationDriver.TryPopulateNextData(out data);
                    
                    return data;
                });

            // QueryRepository is constructed by calling IQueryRepositoryBuilder.CreateQueryRepository
            container.RegisterCustomResolver(
                typeof(QueryRepository),
                t =>
                {
                    var repositoryBuilder = container.Resolve<IQueryRepositoryBuilder>();
                    var workspace = container.Resolve<ODataTestWorkspace>();
                    var queryTypeLibrary = container.Resolve<QueryTypeLibrary>();
                    var entityContaineData = container.Resolve<EntityContainerData>();

//.........这里部分代码省略.........
开发者ID:AlineGuan,项目名称:odata.net,代码行数:101,代码来源:ODataTaupoTestUtils.cs


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