Trigger Controller Method using Hangfire for ASP.NET CoreWhy is it important to override GetHashCode when Equals method is overridden?Dependency injection failure in ASP.NET Core RC2Unable to find Use.RunTimePageInfo() method in startup.cs file in aspnet coreHow do I dynamically choose a connection string based on Environment in .Net Core startup?NullReferenceException when using Fluent Validation ASP.NET CoreCan authentication cookie be shared between two .Net Core 2.0 applications?Can't get my Asp.Net Core project to work published to folder on localhostFailed to load http://localhost:5000/.well-known/openid-configuration: No 'Access-Control-Allow-Origin' header is present on the requested resourceProblem with asp core 2.1 and AWS cognito OIDC connectionHow do I set up 'connectionString' for a mySQL database for Hangfire?

Does ultrasonic bath cleaning damage laboratory volumetric glassware calibration?

Articles before "covenant"?

How hard is it to sell a home which is currently mortgaged?

Declining an offer to present a poster instead of a paper

How do I find and plot the intersection of these three surfaces?

How well known and how commonly used was Huffman coding in 1979?

Should I report a leak of confidential HR information?

Why is a blank required between "[[" and "-e xxx" in ksh?

Intuitively, why does putting capacitors in series decrease the equivalent capacitance?

Wilcoxon signed rank test – critical value for n>50

C-152 carb heat on before landing in hot weather?

Do 3D printers really reach 50 micron (0.050mm) accuracy?

How come I was asked by a CBP officer why I was in the US when leaving?

Should I include salary information on my CV?

What's the point of DHS warning passengers about Manila airport?

Derivative of an algebraic power series in positive characteristic

Does anycast addressing add additional latency in any way?

What does 2>&1 | tee mean?

Sir Alex Ferguson advice OR Sir Alex Ferguson's advice

If protons are the only stable baryons, why do they decay into neutrons in positron emission?

Why does the A-4 Skyhawk sit nose-up when on ground?

MH370 blackbox - is it still possible to retrieve data from it?

How can I create ribbons like these in Microsoft word 2010?

What happens when your group is victim of a surprise attack but you can't be surprised?



Trigger Controller Method using Hangfire for ASP.NET Core


Why is it important to override GetHashCode when Equals method is overridden?Dependency injection failure in ASP.NET Core RC2Unable to find Use.RunTimePageInfo() method in startup.cs file in aspnet coreHow do I dynamically choose a connection string based on Environment in .Net Core startup?NullReferenceException when using Fluent Validation ASP.NET CoreCan authentication cookie be shared between two .Net Core 2.0 applications?Can't get my Asp.Net Core project to work published to folder on localhostFailed to load http://localhost:5000/.well-known/openid-configuration: No 'Access-Control-Allow-Origin' header is present on the requested resourceProblem with asp core 2.1 and AWS cognito OIDC connectionHow do I set up 'connectionString' for a mySQL database for Hangfire?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















Good day guys,



I'm trying to trigger a certain command inside my Controller in ASP.NET Core.



I've installed hangfire and configured my Startup.cs



public void ConfigureServices(IServiceCollection services)

...
services.AddHangfire(x => x.UseSqlServerStorage('my conn string'));
...


public void Configure(IApplicationBuilder app, IHostingEnvironment env)

...
// add hangfire
app.UseHangfireDashboard();
app.UseHangfireServer();
...



But the problem is, my sample controller has multiple dependency injections



public class ProductsController: Controller

private readonly ISomething1 something1;
private readonly ISomething2 something2;
private readonly ISomething3 something3;

public ProductsController(ISomething1 something1, ISomething2 something2, ISomething3 something3)
this.something1 = something1;
this.something2 = something2;
this.something3 = something3;


public async Task<IActionResult> TriggerMe()
...




I'm trying to implement something like this on my startup



RecurringJob.AddOrUpdate(
() => // trigger the TriggerMe() controller method ,
Cron.Daily);


Any help please? Thank you










share|improve this question






















  • As it's a controller method, I'd say the best thing to do here is to actually invoke it via HTTP rather than programatically because then you're leaving the framework do what it should be doing with pipelines and error handling.

    – ColinM
    Mar 25 at 11:49











  • But I need to trigger that Controller Method. to generate my PDF since I'm using Rotativa to generate pdf byte.

    – AppleCiderYummy
    Mar 25 at 11:53











  • what is the purpose of a cron job here then? because Rotavita is specific for generating PDFs from Razor views

    – Aarif
    Mar 25 at 12:02











  • My controller method returns a pdf file using rotativa, that's why I need to trigger it using hangerfire automatically. Using rotativa in a normal class won't work since it needs ControllerContext

    – AppleCiderYummy
    Mar 25 at 12:03











  • I get that, but why trigger PDF generation from hangfire?

    – Aarif
    Mar 25 at 12:05

















0















Good day guys,



I'm trying to trigger a certain command inside my Controller in ASP.NET Core.



I've installed hangfire and configured my Startup.cs



public void ConfigureServices(IServiceCollection services)

...
services.AddHangfire(x => x.UseSqlServerStorage('my conn string'));
...


public void Configure(IApplicationBuilder app, IHostingEnvironment env)

...
// add hangfire
app.UseHangfireDashboard();
app.UseHangfireServer();
...



But the problem is, my sample controller has multiple dependency injections



public class ProductsController: Controller

private readonly ISomething1 something1;
private readonly ISomething2 something2;
private readonly ISomething3 something3;

public ProductsController(ISomething1 something1, ISomething2 something2, ISomething3 something3)
this.something1 = something1;
this.something2 = something2;
this.something3 = something3;


public async Task<IActionResult> TriggerMe()
...




I'm trying to implement something like this on my startup



RecurringJob.AddOrUpdate(
() => // trigger the TriggerMe() controller method ,
Cron.Daily);


Any help please? Thank you










share|improve this question






















  • As it's a controller method, I'd say the best thing to do here is to actually invoke it via HTTP rather than programatically because then you're leaving the framework do what it should be doing with pipelines and error handling.

    – ColinM
    Mar 25 at 11:49











  • But I need to trigger that Controller Method. to generate my PDF since I'm using Rotativa to generate pdf byte.

    – AppleCiderYummy
    Mar 25 at 11:53











  • what is the purpose of a cron job here then? because Rotavita is specific for generating PDFs from Razor views

    – Aarif
    Mar 25 at 12:02











  • My controller method returns a pdf file using rotativa, that's why I need to trigger it using hangerfire automatically. Using rotativa in a normal class won't work since it needs ControllerContext

    – AppleCiderYummy
    Mar 25 at 12:03











  • I get that, but why trigger PDF generation from hangfire?

    – Aarif
    Mar 25 at 12:05













0












0








0








Good day guys,



I'm trying to trigger a certain command inside my Controller in ASP.NET Core.



I've installed hangfire and configured my Startup.cs



public void ConfigureServices(IServiceCollection services)

...
services.AddHangfire(x => x.UseSqlServerStorage('my conn string'));
...


public void Configure(IApplicationBuilder app, IHostingEnvironment env)

...
// add hangfire
app.UseHangfireDashboard();
app.UseHangfireServer();
...



But the problem is, my sample controller has multiple dependency injections



public class ProductsController: Controller

private readonly ISomething1 something1;
private readonly ISomething2 something2;
private readonly ISomething3 something3;

public ProductsController(ISomething1 something1, ISomething2 something2, ISomething3 something3)
this.something1 = something1;
this.something2 = something2;
this.something3 = something3;


public async Task<IActionResult> TriggerMe()
...




I'm trying to implement something like this on my startup



RecurringJob.AddOrUpdate(
() => // trigger the TriggerMe() controller method ,
Cron.Daily);


Any help please? Thank you










share|improve this question














Good day guys,



I'm trying to trigger a certain command inside my Controller in ASP.NET Core.



I've installed hangfire and configured my Startup.cs



public void ConfigureServices(IServiceCollection services)

...
services.AddHangfire(x => x.UseSqlServerStorage('my conn string'));
...


public void Configure(IApplicationBuilder app, IHostingEnvironment env)

...
// add hangfire
app.UseHangfireDashboard();
app.UseHangfireServer();
...



But the problem is, my sample controller has multiple dependency injections



public class ProductsController: Controller

private readonly ISomething1 something1;
private readonly ISomething2 something2;
private readonly ISomething3 something3;

public ProductsController(ISomething1 something1, ISomething2 something2, ISomething3 something3)
this.something1 = something1;
this.something2 = something2;
this.something3 = something3;


public async Task<IActionResult> TriggerMe()
...




I'm trying to implement something like this on my startup



RecurringJob.AddOrUpdate(
() => // trigger the TriggerMe() controller method ,
Cron.Daily);


Any help please? Thank you







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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 25 at 11:41









AppleCiderYummyAppleCiderYummy

8210 bronze badges




8210 bronze badges












  • As it's a controller method, I'd say the best thing to do here is to actually invoke it via HTTP rather than programatically because then you're leaving the framework do what it should be doing with pipelines and error handling.

    – ColinM
    Mar 25 at 11:49











  • But I need to trigger that Controller Method. to generate my PDF since I'm using Rotativa to generate pdf byte.

    – AppleCiderYummy
    Mar 25 at 11:53











  • what is the purpose of a cron job here then? because Rotavita is specific for generating PDFs from Razor views

    – Aarif
    Mar 25 at 12:02











  • My controller method returns a pdf file using rotativa, that's why I need to trigger it using hangerfire automatically. Using rotativa in a normal class won't work since it needs ControllerContext

    – AppleCiderYummy
    Mar 25 at 12:03











  • I get that, but why trigger PDF generation from hangfire?

    – Aarif
    Mar 25 at 12:05

















  • As it's a controller method, I'd say the best thing to do here is to actually invoke it via HTTP rather than programatically because then you're leaving the framework do what it should be doing with pipelines and error handling.

    – ColinM
    Mar 25 at 11:49











  • But I need to trigger that Controller Method. to generate my PDF since I'm using Rotativa to generate pdf byte.

    – AppleCiderYummy
    Mar 25 at 11:53











  • what is the purpose of a cron job here then? because Rotavita is specific for generating PDFs from Razor views

    – Aarif
    Mar 25 at 12:02











  • My controller method returns a pdf file using rotativa, that's why I need to trigger it using hangerfire automatically. Using rotativa in a normal class won't work since it needs ControllerContext

    – AppleCiderYummy
    Mar 25 at 12:03











  • I get that, but why trigger PDF generation from hangfire?

    – Aarif
    Mar 25 at 12:05
















As it's a controller method, I'd say the best thing to do here is to actually invoke it via HTTP rather than programatically because then you're leaving the framework do what it should be doing with pipelines and error handling.

– ColinM
Mar 25 at 11:49





As it's a controller method, I'd say the best thing to do here is to actually invoke it via HTTP rather than programatically because then you're leaving the framework do what it should be doing with pipelines and error handling.

– ColinM
Mar 25 at 11:49













But I need to trigger that Controller Method. to generate my PDF since I'm using Rotativa to generate pdf byte.

– AppleCiderYummy
Mar 25 at 11:53





But I need to trigger that Controller Method. to generate my PDF since I'm using Rotativa to generate pdf byte.

– AppleCiderYummy
Mar 25 at 11:53













what is the purpose of a cron job here then? because Rotavita is specific for generating PDFs from Razor views

– Aarif
Mar 25 at 12:02





what is the purpose of a cron job here then? because Rotavita is specific for generating PDFs from Razor views

– Aarif
Mar 25 at 12:02













My controller method returns a pdf file using rotativa, that's why I need to trigger it using hangerfire automatically. Using rotativa in a normal class won't work since it needs ControllerContext

– AppleCiderYummy
Mar 25 at 12:03





My controller method returns a pdf file using rotativa, that's why I need to trigger it using hangerfire automatically. Using rotativa in a normal class won't work since it needs ControllerContext

– AppleCiderYummy
Mar 25 at 12:03













I get that, but why trigger PDF generation from hangfire?

– Aarif
Mar 25 at 12:05





I get that, but why trigger PDF generation from hangfire?

– Aarif
Mar 25 at 12:05












1 Answer
1






active

oldest

votes


















0














UPDATE

As the Rotavita is tightly coupled with controllers,views etc. I'd recommend solving this problem in two steps



  1. Generate HTML from a view (for reporting/email purposes separate out that view from normal ones) using RazorEngine, you'd only need the view/template path and the model (containing values to be rendered)

  2. Use the HTML to generate a PDF using wkhtmltopdf (Rotavita uses this lib under the hood)


Original



As invoking a controller instance is a process done by the framework and it shouldn't be invoked or called by cron jobs.

For your problem, you just need to add the reference to the method or delegate. Assuming that you're going to move your code to some other class.



var instance=new Foo();
RecurringJob.AddOrUpdate(() => instance.DoSomething,Cron.Daily);


and the Foo class



public class Foo

public void DoSomething()

//your code







share|improve this answer

























  • you don't get my question

    – AppleCiderYummy
    Mar 25 at 11:59











  • It's a Controller class with multiple dependency injections

    – AppleCiderYummy
    Mar 25 at 11:59











  • There's no problem with normal class, but the problem is when you have controller class with dependency injecitons

    – AppleCiderYummy
    Mar 25 at 12:00











  • as I said, something like that shouldn't be done by cron jobs

    – Aarif
    Mar 25 at 12:00











  • "something like that shouldn't be done by cron jobs" - why not?

    – ColinM
    Mar 25 at 13:52













Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55337008%2ftrigger-controller-method-using-hangfire-for-asp-net-core%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














UPDATE

As the Rotavita is tightly coupled with controllers,views etc. I'd recommend solving this problem in two steps



  1. Generate HTML from a view (for reporting/email purposes separate out that view from normal ones) using RazorEngine, you'd only need the view/template path and the model (containing values to be rendered)

  2. Use the HTML to generate a PDF using wkhtmltopdf (Rotavita uses this lib under the hood)


Original



As invoking a controller instance is a process done by the framework and it shouldn't be invoked or called by cron jobs.

For your problem, you just need to add the reference to the method or delegate. Assuming that you're going to move your code to some other class.



var instance=new Foo();
RecurringJob.AddOrUpdate(() => instance.DoSomething,Cron.Daily);


and the Foo class



public class Foo

public void DoSomething()

//your code







share|improve this answer

























  • you don't get my question

    – AppleCiderYummy
    Mar 25 at 11:59











  • It's a Controller class with multiple dependency injections

    – AppleCiderYummy
    Mar 25 at 11:59











  • There's no problem with normal class, but the problem is when you have controller class with dependency injecitons

    – AppleCiderYummy
    Mar 25 at 12:00











  • as I said, something like that shouldn't be done by cron jobs

    – Aarif
    Mar 25 at 12:00











  • "something like that shouldn't be done by cron jobs" - why not?

    – ColinM
    Mar 25 at 13:52















0














UPDATE

As the Rotavita is tightly coupled with controllers,views etc. I'd recommend solving this problem in two steps



  1. Generate HTML from a view (for reporting/email purposes separate out that view from normal ones) using RazorEngine, you'd only need the view/template path and the model (containing values to be rendered)

  2. Use the HTML to generate a PDF using wkhtmltopdf (Rotavita uses this lib under the hood)


Original



As invoking a controller instance is a process done by the framework and it shouldn't be invoked or called by cron jobs.

For your problem, you just need to add the reference to the method or delegate. Assuming that you're going to move your code to some other class.



var instance=new Foo();
RecurringJob.AddOrUpdate(() => instance.DoSomething,Cron.Daily);


and the Foo class



public class Foo

public void DoSomething()

//your code







share|improve this answer

























  • you don't get my question

    – AppleCiderYummy
    Mar 25 at 11:59











  • It's a Controller class with multiple dependency injections

    – AppleCiderYummy
    Mar 25 at 11:59











  • There's no problem with normal class, but the problem is when you have controller class with dependency injecitons

    – AppleCiderYummy
    Mar 25 at 12:00











  • as I said, something like that shouldn't be done by cron jobs

    – Aarif
    Mar 25 at 12:00











  • "something like that shouldn't be done by cron jobs" - why not?

    – ColinM
    Mar 25 at 13:52













0












0








0







UPDATE

As the Rotavita is tightly coupled with controllers,views etc. I'd recommend solving this problem in two steps



  1. Generate HTML from a view (for reporting/email purposes separate out that view from normal ones) using RazorEngine, you'd only need the view/template path and the model (containing values to be rendered)

  2. Use the HTML to generate a PDF using wkhtmltopdf (Rotavita uses this lib under the hood)


Original



As invoking a controller instance is a process done by the framework and it shouldn't be invoked or called by cron jobs.

For your problem, you just need to add the reference to the method or delegate. Assuming that you're going to move your code to some other class.



var instance=new Foo();
RecurringJob.AddOrUpdate(() => instance.DoSomething,Cron.Daily);


and the Foo class



public class Foo

public void DoSomething()

//your code







share|improve this answer















UPDATE

As the Rotavita is tightly coupled with controllers,views etc. I'd recommend solving this problem in two steps



  1. Generate HTML from a view (for reporting/email purposes separate out that view from normal ones) using RazorEngine, you'd only need the view/template path and the model (containing values to be rendered)

  2. Use the HTML to generate a PDF using wkhtmltopdf (Rotavita uses this lib under the hood)


Original



As invoking a controller instance is a process done by the framework and it shouldn't be invoked or called by cron jobs.

For your problem, you just need to add the reference to the method or delegate. Assuming that you're going to move your code to some other class.



var instance=new Foo();
RecurringJob.AddOrUpdate(() => instance.DoSomething,Cron.Daily);


and the Foo class



public class Foo

public void DoSomething()

//your code








share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 25 at 13:04

























answered Mar 25 at 11:58









AarifAarif

6127 silver badges18 bronze badges




6127 silver badges18 bronze badges












  • you don't get my question

    – AppleCiderYummy
    Mar 25 at 11:59











  • It's a Controller class with multiple dependency injections

    – AppleCiderYummy
    Mar 25 at 11:59











  • There's no problem with normal class, but the problem is when you have controller class with dependency injecitons

    – AppleCiderYummy
    Mar 25 at 12:00











  • as I said, something like that shouldn't be done by cron jobs

    – Aarif
    Mar 25 at 12:00











  • "something like that shouldn't be done by cron jobs" - why not?

    – ColinM
    Mar 25 at 13:52

















  • you don't get my question

    – AppleCiderYummy
    Mar 25 at 11:59











  • It's a Controller class with multiple dependency injections

    – AppleCiderYummy
    Mar 25 at 11:59











  • There's no problem with normal class, but the problem is when you have controller class with dependency injecitons

    – AppleCiderYummy
    Mar 25 at 12:00











  • as I said, something like that shouldn't be done by cron jobs

    – Aarif
    Mar 25 at 12:00











  • "something like that shouldn't be done by cron jobs" - why not?

    – ColinM
    Mar 25 at 13:52
















you don't get my question

– AppleCiderYummy
Mar 25 at 11:59





you don't get my question

– AppleCiderYummy
Mar 25 at 11:59













It's a Controller class with multiple dependency injections

– AppleCiderYummy
Mar 25 at 11:59





It's a Controller class with multiple dependency injections

– AppleCiderYummy
Mar 25 at 11:59













There's no problem with normal class, but the problem is when you have controller class with dependency injecitons

– AppleCiderYummy
Mar 25 at 12:00





There's no problem with normal class, but the problem is when you have controller class with dependency injecitons

– AppleCiderYummy
Mar 25 at 12:00













as I said, something like that shouldn't be done by cron jobs

– Aarif
Mar 25 at 12:00





as I said, something like that shouldn't be done by cron jobs

– Aarif
Mar 25 at 12:00













"something like that shouldn't be done by cron jobs" - why not?

– ColinM
Mar 25 at 13:52





"something like that shouldn't be done by cron jobs" - why not?

– ColinM
Mar 25 at 13:52



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55337008%2ftrigger-controller-method-using-hangfire-for-asp-net-core%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해