/// <summary> /// EntityWorks middleware registration. /// </summary> public static IApplicationBuilder UseEntityWorks(this IApplicationBuilder app, Action <EntityWorksOptions> options) { // Validate options instance. if (options == null) { throw new ArgumentNullException("options", "EntityWorksOptions can not be null. "); } // Set entity works provider for scoped instance. EntityWorksContextProvider.SetEntityWorksContextFactory(() => { // Get httpcontext accessor. var httpContextAccessor = app.ApplicationServices.GetRequiredService <IHttpContextAccessor>(); // Get entitworks service. return(httpContextAccessor.HttpContext.RequestServices.GetRequiredService <EntityWorksContext>()); }); // Create options. var _options = new EntityWorksOptions(); // Configure options. options(_options); // Use entityworks middleware. app.UseMiddleware <EntityWorksMiddleware>(options); // Return app builder. return(app); }
/// <summary> /// EntityWorks middleware registration. /// </summary> public static IApplicationBuilder UseEntityWorks(this IApplicationBuilder app) { // Set entity works provider for scoped instance. EntityWorksContextProvider.SetEntityWorksContextFactory(() => { // Get httpcontext accessor. var httpContextAccessor = app.ApplicationServices.GetRequiredService <IHttpContextAccessor>(); // Get entitworks service. return(httpContextAccessor.HttpContext.RequestServices.GetRequiredService <EntityWorksContext>()); }); // Create default options. var _options = new EntityWorksOptions(); // Use entityworks middleware. app.UseMiddleware <EntityWorksMiddleware>(_options); // Return app builder. return(app); }
/// <summary> /// Creates entityworks middleware object. /// </summary> /// <param name="options">EntityWorks configuration options</param> public EntityWorksMiddleware(RequestDelegate next, EntityWorksOptions options) { // Set members. this.m_next = next; m_options = options; }