.NET Core 创建Windows服务
2021-06-04 17:02
标签:依赖注入 .net core inter interface var pes set har 示例 作者:高堂 使用 TopShelf+Autofac+AutoMapper+Quartz+NLog 完成现有项目定时调度任务 .NET Core 创建Windows服务 标签:依赖注入 .net core inter interface var pes set har 示例 原文地址:https://www.cnblogs.com/gaotang/p/10850564.html.NET Core 创建Windows服务
原文地址:https://www.cnblogs.com/gaotang/p/10850564.html写在前面
1.相关NetGet包
2.添加Autofac自动映射服务
3.添加AutoMapper自动映射类
public static class AutoMapperExtensions
{
public static ContainerBuilder ConfigureAutoMapper(this ContainerBuilder builder)
{
builder.RegisterAssemblyTypes(AppDomain.CurrentDomain.GetAssemblies())
.AsClosedTypesOf(typeof(ITypeConverter))
.AsImplementedInterfaces();
builder.RegisterAssemblyTypes(typeof(AutoMapperExtensions).Assembly)
.AssignableTo
public static class ServicesExtensions
{
public static ContainerBuilder ConfigureSelf(this ContainerBuilder builder)
{
var services = new ServiceCollection();
// register appsettings.json
services.Configure
4.添加Quartz调度任务
public static ContainerBuilder ConfigureQuartz(this ContainerBuilder builder)
{
// 1) Register IScheduler
builder.RegisterModule(new QuartzAutofacFactoryModule());
// 2) Register jobs
builder.RegisterModule(new QuartzAutofacJobsModule(typeof(MyJob1).Assembly));
return builder;
}
5.添加日志
6.创建TopShelf服务
7.发布并添加Windows服务
cd /d %~dp0
Sample.Topshelf.exe install
pause
cd /d %~dp0
Sample.Topshelf.exe uninstall
pause
源码
参考资料