hangfire 초기화 작업 메커니즘
9493 단어 초기화
hangfire 초기화 구성 방법: UseHangfire.
public static class OwinBootstrapper
{
/// <summary>
/// Bootstraps Hangfire components using the given configuration
/// action and maps Hangfire Dashboard to the app builder pipeline
/// at the configured path ('/hangfire' by default).
/// </summary>
/// <param name="app">The app builder</param>
/// <param name="configurationAction">Configuration action</param>
public static void UseHangfire([NotNull] this IAppBuilder app,[NotNull] Action<IBootstrapperConfiguration> configurationAction)
{
if (app == null) throw new ArgumentNullException("app");
if (configurationAction == null) throw new ArgumentNullException("configurationAction");
// ,
var configuration = new BootstrapperConfiguration();
//
configurationAction(configuration);
if (configuration.Activator != null)
{
JobActivator.Current = configuration.Activator;
}
if (configuration.Storage == null)
{
throw new InvalidOperationException("Job storage was not configured. Please call either `UseStorage` method or its overloads.");
}
//
JobStorage.Current = configuration.Storage;
// UseFilter()
foreach (var filter in configuration.Filters)
{
GlobalJobFilters.Filters.Add(filter);
}
// UseServers() , , server
foreach (var server in configuration.Servers)
{
app.RunHangfireServer(server());
}
// Route filter owin
app.MapHangfireDashboard(configuration.DashboardPath, configuration.AuthorizationFilters);
}
}
개발자가 직접 Ibootstrapper Configuration 인터페이스를 실현하도록 위탁하는 것이 아니라 위탁하는 방식으로 처리하다
이런 방식은 확실히 개발자가 사용하기에 더욱 편리하다.
public static void MapHangfireDashboard(
[NotNull] this IAppBuilder app,
string dashboardPath,
IEnumerable<IAuthorizationFilter> authorizationFilters,
JobStorage storage)
{
if (app == null) throw new ArgumentNullException("app");
SignatureConversions.AddConversions(app);
app.Map(dashboardPath,subApp => subApp.Use<DashboardMiddleware>(
storage,
DashboardRoutes.Routes,
authorizationFilters));
}
MapHangfireDashboard DashboardMiddleware own
dashboardPath “/hangfire” , Http://www.xxx.com/hangfire DashboardMiddleware
DashboardMiddleware OwinMiddleware
// DashboardMiddleware
public override Task Invoke(IOwinContext context)
{
// RouteCollection ,
var dispatcher = _routes.FindDispatcher(context.Request.Path.Value);
if (dispatcher == null)
{
// OwinMiddleware
// OwinMiddleware
return Next.Invoke(context);
}
foreach (var filter in _authorizationFilters)
{
if (!filter.Authorize(context.Environment))
{
context.Response.StatusCode = (int) HttpStatusCode.Unauthorized;
return Task.FromResult(false);
}
}
//
var dispatcherContext = new RequestDispatcherContext(
_storage,
context.Environment,
dispatcher.Item2);
return dispatcher.Item1.Dispatch(dispatcherContext);
}
RequestDispatcherContext , , 。
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
WordPress 초기화플러그인을 사용하여 쉽게 초기화할 수 있습니다. 플러그인은 무엇입니까? 이를 위해 설치 및 활성화 및 초기화 방법을 설명합니다. 플러그인 설치 사이드바 플러그인을 클릭하고 맨 위에 있는 새로 추가를 클릭합니다. 메뉴...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.