Skip to content

Commit

Permalink
fix(plugins/hangfireplugin/hangfireplugin.cs): job execution not work…
Browse files Browse the repository at this point in the history
…ing in dynamically loaded ass
  • Loading branch information
yiyungent committed Jan 25, 2024
1 parent a9d5705 commit 430946e
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion plugins/HangfirePlugin/HangfirePlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,41 @@ public void ConfigureServices(IServiceCollection services)
.UseSQLiteStorage(nameOrConnectionString: dbFilePath, options: new SQLiteStorageOptions()
{

}));
})
// https://github.com/HangfireIO/Hangfire/issues/470
.UseTypeResolver((typeName) =>
{
try
{
return Hangfire.Common.TypeHelper.DefaultTypeResolver(typeName); //try using default resolver
}
catch (Exception) //if couldn't find
{
//get it from AppDomain loaded assemblies.
var reqType = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypes().Where(x => typeName.StartsWith(x.FullName))).FirstOrDefault();

if (reqType != null)
return reqType;

throw;
}
})
);

// Add the processing server as IHostedService
services.AddHangfireServer();

// https://github.com/HangfireIO/Hangfire/issues/470
//Hangfire.Common.TypeHelper.CurrentTypeResolver += typeName =>
//{
// if (typeName.Contains("MyCompany.Services.Messaging"))
// {
// // Load assembly from the specific place and use it to find the type
// return Assembly.GetType(typeName);
// }

// return TypeHelper.DefaultTypeResolver(typeName);
//};
}

public int ConfigureServicesOrder => -999;
Expand Down

0 comments on commit 430946e

Please sign in to comment.