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


C# DependencyInjectionContainer.TryResolve方法代码示例

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


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

示例1: 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


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