Esempio n. 1
0
        public static List <APIEntity> Init <T>(AutoAPIOptions options) where T : DbContext
        {
            AutoAPIOptions = options;

            return((from p in typeof(T).GetProperties()
                    let g = p.PropertyType.GetGenericArguments()
                            let a = p.GetCustomAttribute <AutoAPIEntity>()
                                    where p.IsDefined(typeof(AutoAPIEntity)) && g.Count() == 1
                                    select new APIEntity()
            {
                Route = (new PathString(options.Path)).Add(a.Route.StartsWith("/") ? a.Route : $"/{a.Route}"),
                GETPolicy = a.GETPolicy,
                POSTPolicy = a.POSTPolicy,
                PUTPolicy = a.PUTPolicy,
                DELETEPolicy = a.DELETEPolicy,
                EntityPolicy = a.EntityPolicy,
                Authorize = a.Authorize,
                DbSet = p,
                EntityType = g.First(),
                Properties = g.First().GetProperties().Where(x => x.PropertyType.IsTypeSupported()).ToList(),
                NavigationProperties = g.First().GetProperties().Where(x => !x.PropertyType.IsTypeSupported()).ToList(),
                Id = g.First().GetProperties().Where(x => x.IsDefined(typeof(KeyAttribute))).FirstOrDefault(),
                DbContextType = typeof(T),
                ExposePagedResult = a.ExposePagedResult
            }).ToList());
        }
Esempio n. 2
0
        public static void AddAutoAPI <T>(this IServiceCollection serviceCollection, Action <AutoAPIOptions> options) where T : DbContext
        {
            var op = new AutoAPIOptions();

            options(op);
            AutoAPIEntityCache.AddRange(Init <T>(op));
            serviceCollection.AddTransient <IRequestProcessor, RequestProcessor>();
        }