网站设计方案定制,工装公司排名,网站在工信部备案,html5做静态网站CoravelCoravel是.NetCore中开源的工具库#xff0c;可以让你使用定时任务#xff0c;缓存#xff0c;队列#xff0c;事件#xff0c;广播等高级应用程序变得轻而易举#xff01;Coravel 帮助开发人员在不影响代码质量的情况下快速启动和运行他们的 .NET Core 应用程序。… CoravelCoravel是.NetCore中开源的工具库可以让你使用定时任务缓存队列事件广播等高级应用程序变得轻而易举Coravel 帮助开发人员在不影响代码质量的情况下快速启动和运行他们的 .NET Core 应用程序。它通过为您提供简单、富有表现力和直接的语法使高级应用程序功能易于访问和使用。Github地址:https://github.com/jamesmh/coravel安装dotnet add package coravel例子Task Scheduling配置在 .NET Core 应用程序的Startup.cs文件中在ConfigureServices()方法内添加以下内容services.AddScheduler()使用然后在Configure()方法中可以使用调度器var provider app.ApplicationServices;
provider.UseScheduler(scheduler
{scheduler.Schedule(() Console.WriteLine(Every minute during the week.)).EveryMinute().Weekday();
});Queuing配置在您的Startup文件中在ConfigureServices()services.AddQueue();使用将接口的一个实例Coravel.Queuing.Interfaces.IQueue注入到控制器IQueue _queue;public HomeController(IQueue queue) {this._queue queue;
}同步public IActionResult QueueTask() {this._queue.QueueTask(() Console.WriteLine(This was queued!));return Ok();
}异步this._queue.QueueAsyncTask(async() {await Task.Delay(1000);Console.WriteLine(This was queued!);});Caching配置在Startup.ConfigureServices()services.AddCache();这将启用内存 (RAM) 缓存。使用要使用缓存请Coravel.Cache.Interfaces.ICache通过依赖注入进行注入。private ICache _cache;public CacheController(ICache cache)
{this._cache cache;
}Event Broadcasting事件广播Coravel 的事件广播允许侦听器订阅应用程序中发生的事件。配置在ConfigureServices方法中services.AddEvents();接下来在Configure方法中var provider app.ApplicationServices;
IEventRegistration registration provider.ConfigureEvents();注册事件及其监听器registration.RegisterBlogPostCreated().SubscribeTweetNewPost().SubscribeNotifyEmailSubscribersOfNewPost();使用创建一个实现接口的类Coravel.Events.Interfaces.IEvent。就是这样事件只是将提供给每个侦听器的数据对象。它应该公开与此特定事件关联的数据。例如一个BlogPostCreated事件应该接受BlogPost创建的然后通过公共属性公开它。public class BlogPostCreated : IEvent
{public BlogPost Post { get; set; }public BlogPostCreated(BlogPost post){this.Post post;}
}创建一个新类该类实现您将要监听的事件Coravel.Events.Interfaces.IListener的接口。提示:每个侦听器只能与一个事件相关联。该IListener接口需要您实现HandleAsync(TEvent broadcasted)。创建一个名为TweetNewPost的侦听器public class TweetNewPost : IListenerBlogPostCreated
{private TweetingService _tweeter;public TweetNewPost(TweetingService tweeter){this._tweeter tweeter;}public async Task HandleAsync(BlogPostCreated broadcasted){var post broadcasted.Post;await this._tweeter.TweetNewPost(post);}
}Mailing配置nuget 安装 coravel mail 这将安装 Nuget 包Coravel.Mailer并为您搭建一些基本文件~/Views/Mail/_ViewStart.cshtml- 配置邮件视图以使用 Coravel 的电子邮件模板~/Views/Mail/_ViewImports.cshtml- 允许您使用 Coravel 的视图组件 -~/Views/Mail/Example.cshtml- 示例邮件视图~/Mailables/Example.cs- 可邮寄样本在Startup.ConfigureServices()services.AddMailer(this.Configuration);使用Coravel 使用Mailables发送邮件。Mailables 继承Coravel.Mailer.Mail.Mailable并接受一个泛型类型该类型表示您希望与发送邮件相关联的模型。using Coravel.Mailer.Mail;
using App.Models;namespace App.Mailables
{public class NewUserViewMailable : MailableUserModel{private UserModel _user;public NewUserViewMailable(UserModel user) this._user user;public override void Build(){this.To(this._user).From(fromtest.com).View(~/Views/Mail/NewUser.cshtml, this._user);}}
}Mailable 的所有配置都在该Build()方法中完成。然后您可以调用各种方法例如To和From来配置收件人、发件人等。如果大家对.net开源项目感兴趣可以持续关注我。