小编Moc*_*tfi的帖子

有没有更好的方法在ASP.net核心上使用hangfire和structuremap?

我在asp.net核心上使用了与hangfire的结构图,在应用程序上没有错误,但是即使数据已经在数据库上,也没有处理队列/调度任务.这是我的代码段配置

public IServiceProvider ConfigureServices(IServiceCollection services)
    {
        // setup automapper
        var config = new AutoMapper.MapperConfiguration(cfg =>
        {
            cfg.AddProfile(new AutoMapperProfileConfiguration());
        });

        var mapper = config.CreateMapper();
        services.AddSingleton(mapper);


        // Bind settings parameter
        services.Configure<AppSettings>(Configuration.GetSection("AppSettings"));

        // Add framework services.
        services.AddApplicationInsightsTelemetry(Configuration);
        services.Configure<RouteOptions>(options => options.LowercaseUrls = true);
        services.AddDbContext<DefaultContext>(options =>
            options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

        services.AddHangfire(options => 
            options.UseSqlServerStorage(Configuration.GetConnectionString("DefaultConnection")));

        services.AddMvc();
        // ASP.NET use the StructureMap container to resolve its services.
        return ConfigureIoC(services);
    }

    public IServiceProvider ConfigureIoC(IServiceCollection services)
    {
        var container = new Container();

        GlobalConfiguration.Configuration.UseStructureMapActivator(container);

        container.Configure(config =>
        {
            // Register stuff in container, using the …
Run Code Online (Sandbox Code Playgroud)

c# structuremap asp.net hangfire asp.net-core

9
推荐指数
1
解决办法
1118
查看次数

标签 统计

asp.net ×1

asp.net-core ×1

c# ×1

hangfire ×1

structuremap ×1