Ejemplo n.º 1
0
        /// <summary>
        /// Sets the connections needed by Alessa.
        /// </summary>
        /// <param name="services">The services collection.</param>
        /// <param name="options">Options.</param>
        /// <returns></returns>
        public static IServiceCollection SetAlessaConnections(this IServiceCollection services, Action <QueryBuilderOptions> options)
        {
            QueryBuilderOptions builderOptions = new QueryBuilderOptions();

            options?.Invoke(builderOptions);
            services.AddSingleton(builderOptions);
            services.Configure(options);
            return(services);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds a new connection.
        /// </summary>
        /// <typeparam name="TConnection"></typeparam>
        /// <param name="options"></param>
        /// <param name="cnnName"></param>
        /// <param name="cnnString"></param>
        public static void AddConnection <TConnection>(this QueryBuilderOptions options, string cnnName, string cnnString)
            where TConnection : IDbConnection, new()
        {
            TConnection connection = new TConnection()
            {
                ConnectionString = cnnString
            };

            Compiler     compiler     = GetCompiler <TConnection>();
            QueryFactory queryFactory = new QueryFactory(connection, compiler);

#if DEBUG
            queryFactory.Logger = e => System.Diagnostics.Debug.WriteLine(e);
#endif

            options?.ConnectionsPool.Add(cnnName, queryFactory);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Sets a logger.
 /// </summary>
 /// <param name="options">The builder options.</param>
 /// <param name="logger">The logger to set.</param>
 public static void SetLogger(this QueryBuilderOptions options, ILogger logger)
 {
     options.Logger = logger ?? throw new ArgumentNullException(nameof(logger));
 }