コード例 #1
0
        public static void UseAutoController <T>(
            this IApplicationBuilder appBuilder,
            string routePrefix,
            bool useLogging,
            DatabaseTypes databaseType,
            string connectionString,
            InteractingType?interactingType,
            string authentificationPath,
            string accessDeniedPath,
            JsonSerializerOptions jsonOptions    = null,
            string DefaultGetAction              = "Index",
            string DefaultGetCountAction         = "Count",
            string DefaultPostAction             = "Save",
            string DefaultDeleteAction           = "Delete",
            string DefaultFilterParameter        = "filter",
            string DefaultSortParameter          = "sort",
            string DefaultSortDirectionParameter = "sortdirection",
            string DefaultPageParameter          = "page",
            string DefaultItemsPerPageParameter  = "size",
            string DefaultUpdateAction           = "Update"
            ) where T : DbContext
        {
            if (appBuilder == null)
            {
                throw new ArgumentNullException(nameof(appBuilder));
            }
            var logger = GetOrCreateLogger(appBuilder, LogCategoryName);
            AutoRouterService <T> autoRouter = GetAutoRouterService <T>(appBuilder);

            if (useLogging)
            {
                autoRouter.AttachToLogger(logger);
            }
            autoRouter.GetAutoControllers(
                routePrefix,
                databaseType,
                connectionString,
                interactingType,
                authentificationPath,
                accessDeniedPath,
                jsonOptions,
                DefaultGetAction,
                DefaultGetCountAction,
                DefaultPostAction,
                DefaultDeleteAction,
                DefaultFilterParameter,
                DefaultSortParameter,
                DefaultSortDirectionParameter,
                DefaultPageParameter,
                DefaultItemsPerPageParameter,
                DefaultUpdateAction);
            foreach (var route in autoRouter.Autoroutes)
            {
                AddRoute(appBuilder, route.Key, route.Value);
            }
        }
コード例 #2
0
        /// <summary>
        /// Adds AutoController as singletone service and register it in Dependency Injection
        ///
        /// </summary>
        /// <typeparam name="T">The type of your DBContext/>.</typeparam>
        /// <param name="services">The <see cref="IServiceCollection"/>.</param>
        /// <param name="dbType">The type of Database</param>
        /// <param name="connString">Connection string</param>
        /// <param name="DbContextBeforeSaveChangesMethod">Method of DbContext to execute it before save data</param>
        /// <param name="DbContextFactory">Custom DbContextFactory</param>
        public static void AddAutoController <T>(this IServiceCollection services, DatabaseTypes dbType, string connString, MethodInfo DbContextBeforeSaveChangesMethod = null, Func <T> DbContextFactory = null) where T : DbContext
        {
            AutoRouterService <T> .SetStaticParams(dbType, connString, DbContextBeforeSaveChangesMethod, DbContextFactory);

            services.AddSingleton(typeof(AutoRouterService <T>));
        }