Ejemplo n.º 1
0
        public static void AddJsonApiInternals <TContext>(
            this IServiceCollection services,
            JsonApiOptions jsonApiOptions) where TContext : DbContext
        {
            if (jsonApiOptions.ContextGraph == null)
            {
                jsonApiOptions.BuildContextGraph <TContext>(null);
            }

            services.AddScoped(typeof(DbContext), typeof(TContext));
            AddJsonApiInternals(services, jsonApiOptions);
        }
Ejemplo n.º 2
0
        public static void AddJsonApiInternals <TContext>(
            this IServiceCollection services,
            JsonApiOptions jsonApiOptions) where TContext : DbContext
        {
            if (jsonApiOptions.ContextGraph == null)
            {
                jsonApiOptions.BuildContextGraph <TContext>(null);
            }

            services.AddScoped <IDbContextResolver, DbContextResolver <TContext> >();

            AddJsonApiInternals(services, jsonApiOptions);
        }
Ejemplo n.º 3
0
        public static IServiceCollection AddJsonApi <TContext>(
            this IServiceCollection services,
            Action <JsonApiOptions> options,
            IMvcCoreBuilder mvcBuilder) where TContext : DbContext
        {
            var config = new JsonApiOptions();

            options(config);

            config.BuildContextGraph(builder => builder.AddDbContext <TContext>());

            mvcBuilder.AddMvcOptions(opt => AddMvcOptions(opt, config));

            AddJsonApiInternals <TContext>(services, config);
            return(services);
        }
        public static void AddJsonApi <TContext>(this IServiceCollection services,
                                                 Action <JsonApiOptions> options,
                                                 IMvcBuilder mvcBuilder) where TContext : DbContext
        {
            var config = new JsonApiOptions();

            options(config);

            config.BuildContextGraph(builder => builder.AddDbContext <TContext>());

            mvcBuilder
            .AddMvcOptions(opt =>
            {
                opt.Filters.Add(typeof(JsonApiExceptionFilter));
                opt.SerializeAsJsonApi(config);
            });

            AddJsonApiInternals <TContext>(services, config);
        }
        public DocumentBuilder_Tests()
        {
            _jsonApiContextMock = new Mock <IJsonApiContext>();
            _requestMetaMock    = new Mock <IRequestMeta>();

            _options = new JsonApiOptions();

            _options.BuildContextGraph(builder =>
            {
                builder.AddResource <Model>("models");
                builder.AddResource <RelatedModel>("related-models");
            });

            _jsonApiContextMock
            .Setup(m => m.Options)
            .Returns(_options);

            _jsonApiContextMock
            .Setup(m => m.ContextGraph)
            .Returns(_options.ContextGraph);

            _jsonApiContextMock
            .Setup(m => m.MetaBuilder)
            .Returns(new MetaBuilder());

            _pageManager = new PageManager();
            _jsonApiContextMock
            .Setup(m => m.PageManager)
            .Returns(_pageManager);

            _jsonApiContextMock
            .Setup(m => m.BasePath)
            .Returns("localhost");

            _jsonApiContextMock
            .Setup(m => m.RequestEntity)
            .Returns(_options.ContextGraph.GetContextEntity(typeof(Model)));
        }