public void Configuration(IAppBuilder app) { var configuration = new JsonApiConfiguration(); configuration.RegisterEntityFrameworkResourceType<Building>(); configuration.RegisterEntityFrameworkResourceType<City>(); configuration.RegisterEntityFrameworkResourceType<Comment>(); configuration.RegisterEntityFrameworkResourceType<Company>(); configuration.RegisterEntityFrameworkResourceType<Language>(); configuration.RegisterEntityFrameworkResourceType<LanguageUserLink>(c => { c.OverrideDefaultFilterById(LanguageUserLinkFilterByIdFactory); c.OverrideDefaultSortById(LanguageUserLinkSortByIdFactory); }); configuration.RegisterResourceType<Post>(); configuration.RegisterEntityFrameworkResourceType<State>(); configuration.RegisterEntityFrameworkResourceType<Tag>(); configuration.RegisterEntityFrameworkResourceType<User>(); configuration.RegisterEntityFrameworkResourceType<UserGroup>(); configuration.RegisterResourceType<Sample>(); // Example of a resource type not controlled by EF configuration.RegisterMappedType<Starship, StarshipDto, StarshipDocumentMaterializer>(c => { c.ConfigureRelationship(s => s.Officers, rc => rc.UseMaterializer<StarshipOfficersRelatedResourceMaterializer>()); c.ConfigureRelationship(s => s.ShipCounselor, rc => rc.UseMaterializer<StarshipShipCounselorRelatedResourceMaterializer>()); }); // Example of a resource that is mapped from a DB entity configuration.RegisterResourceType<StarshipOfficerDto>(); var configurator = new JsonApiHttpAutofacConfigurator(); configurator.OnApplicationLifetimeScopeCreating(builder => { builder.Register(c => _dbContextFactory()) .AsSelf() .As<DbContext>() .InstancePerRequest(); builder.RegisterModule<JsonApiAutofacEntityFrameworkModule>(); builder.RegisterType<CustomEntityFrameworkResourceObjectMaterializer>() .As<IEntityFrameworkResourceObjectMaterializer>(); builder.RegisterApiControllers(Assembly.GetExecutingAssembly()); }); configurator.OnApplicationLifetimeScopeBegun(applicationLifetimeScope => { // TODO: is this a candidate for spinning into a JSONAPI.Autofac.WebApi.Owin package? Yuck app.UseAutofacMiddleware(applicationLifetimeScope); }); var httpConfig = new HttpConfiguration { IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always }; // Additional Web API routes httpConfig.Routes.MapHttpRoute("Samples", "samples", new { Controller = "Samples" }); httpConfig.Routes.MapHttpRoute("Search", "search", new { Controller = "Search" }); httpConfig.Routes.MapHttpRoute("Trees", "trees", new { Controller = "Trees" }); configurator.Apply(httpConfig, configuration); app.UseWebApi(httpConfig); app.UseAutofacWebApi(httpConfig); }
/// <summary> /// Build up the <see cref="JsonApiConfiguration"/> which registers all the model types and their mappings. /// </summary> /// <returns></returns> internal JsonApiConfiguration BuildConfiguration() { var configuration = new JsonApiConfiguration( new Core.PluralizationService( new Dictionary <string, string> { { "Child", "Children" } })); configuration.RegisterEntityFrameworkResourceType <Building>(); configuration.RegisterEntityFrameworkResourceType <City>(); configuration.RegisterEntityFrameworkResourceType <Comment>(); configuration.RegisterEntityFrameworkResourceType <Company>(); configuration.RegisterEntityFrameworkResourceType <Language>(); configuration.RegisterEntityFrameworkResourceType <LanguageUserLink>(c => { c.OverrideDefaultFilterById(LanguageUserLinkFilterByIdFactory); c.OverrideDefaultSortById(LanguageUserLinkSortByIdFactory); }); configuration.RegisterResourceType <Post>(); configuration.RegisterResourceType <PostID>(); configuration.RegisterResourceType <PostLongId>(); configuration.RegisterEntityFrameworkResourceType <State>(); configuration.RegisterEntityFrameworkResourceType <Tag>(); configuration.RegisterEntityFrameworkResourceType <User>(); configuration.RegisterEntityFrameworkResourceType <UserGroup>(); configuration.RegisterResourceType <Sample>(); // Example of a resource type not controlled by EF configuration.RegisterMappedType <Starship, StarshipDto, StarshipDocumentMaterializer>(c => { c.ConfigureRelationship(s => s.Officers, rc => rc.UseMaterializer <StarshipOfficersRelatedResourceMaterializer>()); c.ConfigureRelationship(s => s.ShipCounselor, rc => rc.UseMaterializer <StarshipShipCounselorRelatedResourceMaterializer>()); }); // Example of a resource that is mapped from a DB entity configuration.RegisterResourceType <StarshipOfficerDto>(); configuration.RegisterEntityFrameworkResourceType <Master>(); configuration.RegisterEntityFrameworkResourceType <Child>(); configuration.RegisterResourceType <PostSearch>().ResolveCollectionWith <PostSearchResourceQueryResolver>(); configuration.RegisterResourceType <CommentSearch>().ResolveCollectionWith <CommentSearchResourceQueryResolver>(); return(configuration); }
public void Configuration(IAppBuilder app) { var configuration = new JsonApiConfiguration(); configuration.RegisterEntityFrameworkResourceType <Building>(); configuration.RegisterEntityFrameworkResourceType <City>(); configuration.RegisterEntityFrameworkResourceType <Comment>(); configuration.RegisterEntityFrameworkResourceType <Company>(); configuration.RegisterEntityFrameworkResourceType <Language>(); configuration.RegisterEntityFrameworkResourceType <LanguageUserLink>(c => { c.OverrideDefaultFilterById(LanguageUserLinkFilterByIdFactory); c.OverrideDefaultSortById(LanguageUserLinkSortByIdFactory); }); configuration.RegisterResourceType <Post>(); configuration.RegisterEntityFrameworkResourceType <State>(); configuration.RegisterEntityFrameworkResourceType <Tag>(); configuration.RegisterEntityFrameworkResourceType <User>(); configuration.RegisterEntityFrameworkResourceType <UserGroup>(); configuration.RegisterResourceType <Sample>(); // Example of a resource type not controlled by EF configuration.RegisterMappedType <Starship, StarshipDto, StarshipDocumentMaterializer>(c => { c.ConfigureRelationship(s => s.Officers, rc => rc.UseMaterializer <StarshipOfficersRelatedResourceMaterializer>()); c.ConfigureRelationship(s => s.ShipCounselor, rc => rc.UseMaterializer <StarshipShipCounselorRelatedResourceMaterializer>()); }); // Example of a resource that is mapped from a DB entity configuration.RegisterResourceType <StarshipOfficerDto>(); var configurator = new JsonApiHttpAutofacConfigurator(); configurator.OnApplicationLifetimeScopeCreating(builder => { builder.Register(c => _dbContextFactory()) .AsSelf() .As <DbContext>() .InstancePerRequest(); builder.RegisterModule <JsonApiAutofacEntityFrameworkModule>(); builder.RegisterType <CustomEntityFrameworkResourceObjectMaterializer>() .As <IEntityFrameworkResourceObjectMaterializer>(); builder.RegisterApiControllers(Assembly.GetExecutingAssembly()); }); configurator.OnApplicationLifetimeScopeBegun(applicationLifetimeScope => { // TODO: is this a candidate for spinning into a JSONAPI.Autofac.WebApi.Owin package? Yuck app.UseAutofacMiddleware(applicationLifetimeScope); }); var httpConfig = new HttpConfiguration { IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always }; // Additional Web API routes httpConfig.Routes.MapHttpRoute("Samples", "samples", new { Controller = "Samples" }); httpConfig.Routes.MapHttpRoute("Search", "search", new { Controller = "Search" }); httpConfig.Routes.MapHttpRoute("Trees", "trees", new { Controller = "Trees" }); configurator.Apply(httpConfig, configuration); app.UseWebApi(httpConfig); app.UseAutofacWebApi(httpConfig); }