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;
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
|
show 7 more comments
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
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
|
show 7 more comments
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
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
c# asp.net-core asp.net-core-2.0 hangfire
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
|
show 7 more comments
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
|
show 7 more comments
1 Answer
1
active
oldest
votes
UPDATE
As the Rotavita is tightly coupled with controllers,views etc. I'd recommend solving this problem in two steps
- 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)
- Use the HTML to generate a PDF using wkhtmltopdf (
Rotavitauses 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
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
|
show 2 more comments
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
UPDATE
As the Rotavita is tightly coupled with controllers,views etc. I'd recommend solving this problem in two steps
- 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)
- Use the HTML to generate a PDF using wkhtmltopdf (
Rotavitauses 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
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
|
show 2 more comments
UPDATE
As the Rotavita is tightly coupled with controllers,views etc. I'd recommend solving this problem in two steps
- 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)
- Use the HTML to generate a PDF using wkhtmltopdf (
Rotavitauses 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
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
|
show 2 more comments
UPDATE
As the Rotavita is tightly coupled with controllers,views etc. I'd recommend solving this problem in two steps
- 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)
- Use the HTML to generate a PDF using wkhtmltopdf (
Rotavitauses 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
UPDATE
As the Rotavita is tightly coupled with controllers,views etc. I'd recommend solving this problem in two steps
- 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)
- Use the HTML to generate a PDF using wkhtmltopdf (
Rotavitauses 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
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
|
show 2 more comments
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
|
show 2 more comments
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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