コード例 #1
0
        /// <summary>
        /// Adds the TSQL target renderer to a translator configuration.
        /// </summary>
        /// <param name="config">The instance of the translator configuration.</param>
        /// <param name="configure">The builder of the TSQL target renderer.</param>
        /// <returns>The service collection.</returns>
        public static void AddTsqlTarget(this ITranslatorConfig config, Action <ITargetBuilder> configure = null)
        {
            IServiceCollection services = new ServiceCollection();

            services.AddTsqlTarget();

            TargetBuilder configuration = new TargetBuilder();

            if (configure != null)
            {
                configure(configuration);
            }

            configuration.UpdateServices(services);
            config.AddTarget(typeof(TsqlTargetRenderer), services);
        }
コード例 #2
0
        /// <summary>
        /// Adds the TSQL target renderer to a service collection.
        /// </summary>
        /// <param name="services">The instance of the service collection.</param>
        /// <param name="config">The builder of the TSQL target renderer.</param>
        /// <returns>The service collection.</returns>
        public static IServiceCollection AddTsqlTarget(this IServiceCollection services, Action <ITargetBuilder> config = null)
        {
            services.AddScoped <ITargetRenderer, TsqlTargetRenderer>();
            services.AddScoped <IMapper, Mapper>();
            services.AddScoped <IReferencesManager, ReferencesManager>();
            services.AddScoped <TemporaryTables>();

            services.AddTransient <IJoinSelectBuilder, JoinSelectBuilder>();

            Assembly executingAssembly = Assembly.GetExecutingAssembly();

            IEnumerable <Type> Operators = Assembly
                                           .GetExecutingAssembly()
                                           .GetTypes()
                                           .Where(p => typeof(IOperatorRenderer).IsAssignableFrom(p) && p.IsClass);

            foreach (Type type in Operators)
            {
                services.AddTransient(type);
            }

            services.AddTransient <OperatorRendererResolver>(ServiceProvider => key =>
            {
                Type type = executingAssembly.GetTypes().SingleOrDefault(t => t.GetCustomAttribute <OperatorRendererSymbolAttribute>(true)?.Symbols.Contains(key) == true);

                if (type == null)
                {
                    return(null);
                }

                return((IOperatorRenderer)ServiceProvider.GetService(type));
            });

            TargetBuilder configuration = new TargetBuilder();

            if (config != null)
            {
                config(configuration);
            }

            configuration.UpdateServices(services);

            return(services);
        }