Giter Club home page Giter Club logo

Comments (11)

jamesmh avatar jamesmh commented on July 30, 2024

What version of Coravel are you using?

from coravel.

jamesmh avatar jamesmh commented on July 30, 2024

And what version of .NET core?

from coravel.

JerryMouseLi avatar JerryMouseLi commented on July 30, 2024

Coravel v2.5
.NET core v2.2

from coravel.

JerryMouseLi avatar JerryMouseLi commented on July 30, 2024
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using IBMS.Infrastruct.Redis;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Swashbuckle.AspNetCore.Swagger;
using IBMS.Infrastruct.Context;
using IBMS.Domain.Interfaces;
using Microsoft.EntityFrameworkCore;
using Coravel;
using Coravel.Invocable;

namespace IBMS.WEBAPI
{
    public class Startup
    {
        private const string _defaultCorsPolicyName = "localhost";
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {

            // Add DbContext using SQL Server Provider
            services.AddDbContext<IIPBoxContext, IPBoxContext>(options =>
            options.UseMySql(Configuration.GetConnectionString("MySqlConnection")));

            // services.AddScoped<ICaching, MemoryCaching>();//记得把缓存注入!!!
            //  services.AddScoped<IRedisCacheManager, RedisCacheManager>();//这里说下,如果是自己的项目,个人更建议使用单例模式 services.AddSingleton 
            services.AddScoped<IRedisMQ, RedisMQ>();
            services.AddCors(options => options.AddPolicy(_defaultCorsPolicyName,
                             builder =>
                             builder.AllowAnyOrigin()
                               .AllowAnyHeader()
                               .AllowAnyMethod().AllowCredentials()
                               ));
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            services.AddScheduler();
            #region Swagger
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info
                {
                    Version = "v0.1.0",
                    Title = "IBMS.WEBAPI",
                    Description = "框架接口说明文档",
                    TermsOfService = "None",
                    Contact = new Swashbuckle.AspNetCore.Swagger.Contact { Name = "IBMS.WEBAPI", Email = "[email protected]", Url = "https://www.cnblogs.com/JerryMouseLi/" }


                });

                services.AddScoped<IPBoxContext>();//上下文

                // var basePath = Microsoft.DotNet.PlatformAbstractions.ApplicationEnvironment.ApplicationBasePath;
                // var xmlPath = Path.Combine(basePath, "IBMS.WEBAPI.xml");//这个就是刚刚配置的xml文件名
                // c.IncludeXmlComments(xmlPath, true);//默认的第二个参数是false,这个是controller的注释,记得修改
                // 
                // var xmlModelPath = Path.Combine(basePath, "IBMS.Domain.Models.xml");//这个就是Model层的xml文件名                                         
                // c.IncludeXmlComments(xmlModelPath);



            });

            #endregion
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                // 在开发环境中,使用异常页面,这样可以暴露错误堆栈信息,所以不要放在生产环境。
                app.UseDeveloperExceptionPage();
                #region Swagger
                app.UseSwagger();
                app.UseSwaggerUI(c =>
                {
                    c.SwaggerEndpoint("/swagger/v1/swagger.json", "ApiHelp V1");
                    c.RoutePrefix = "";//路径配置,设置为空,表示直接访问该文件,
                                       //路径配置,设置为空,表示直接在根域名(localhost:8001)访问该文件,注意localhost:8001/swagger是访问不到的,
                                       //这个时候去launchSettings.json中把"launchUrl": "swagger/index.html"去掉, 然后直接访问localhost:8001/index.html即可
                });
                #endregion

            }
            
            
            var provider = app.ApplicationServices;

              provider.UseScheduler(scheduler =>
                  {
                      scheduler.Schedule(() => Console.WriteLine("Every minute during the week."))
                      .EverySecond()
                      .Weekday();
                  });
            app.UseCors(_defaultCorsPolicyName);
            app.UseMvc();
        }

    }

}

This is my total startup.cs file. There is no other configration of Coravel on other files. And when I remove .Weekday(); as follow:

             provider.UseScheduler(scheduler =>
                 {
                     scheduler.Schedule(() => Console.WriteLine("Every minute during the week."))
                     .EverySecond()
             
                 });

It will be ok, no problem. Could you pls kindly help me?

from coravel.

JerryMouseLi avatar JerryMouseLi commented on July 30, 2024

I just do it as per your https://docs.coravel.net/Scheduler/ Config Item.

services.AddScheduler()
var provider = app.ApplicationServices;
provider.UseScheduler(scheduler =>
{
    scheduler.Schedule(
        () => Console.WriteLine("Every minute during the week.")
    )
    .EveryMinute()
    .Weekday();
});

It is ok, no problem, but when I change .EveryMinute() to .EverySecond(), then goes the "System.NullReferenceException:“Object reference not set to an instance of an object.”" on System.Private.CoreLib.dll

from coravel.

jamesmh avatar jamesmh commented on July 30, 2024

Thanks - I'll have a look and get back to you 🙂

from coravel.

JerryMouseLi avatar JerryMouseLi commented on July 30, 2024

Have you repeated it?

from coravel.

jamesmh avatar jamesmh commented on July 30, 2024

So I found the issue, should have a new Nuget package for version 2.5.1 soon 🙂

from coravel.

JerryMouseLi avatar JerryMouseLi commented on July 30, 2024

When will you publish the version 2.5.1 to solve this issue?

from coravel.

jamesmh avatar jamesmh commented on July 30, 2024

Fixed it during my day job break 😋 Coravel users are not always so lucky as you 😂

2.5.1 should be available now.

from coravel.

JerryMouseLi avatar JerryMouseLi commented on July 30, 2024

It is really nice. Thanks very much, jamesmh.

from coravel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.