Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Program
- {
- static void Main()
- {
- var container = new UnityContainer();
- //the instance to be injected
- var systemClient = new JobSystemClient
- {
- UserName = "admin",
- PassWord = "admin1234"
- };
- container.RegisterInstance<ISystemClient>(systemClient);
- //Registration of the Functions class
- container.RegisterType<Functions>();
- var activator = new UnityJobActivator(container);
- var config = new JobHostConfiguration();
- config.JobActivator = activator;
- var host = new JobHost(config);
- // The following code will invoke a function called ManualTrigger and
- // pass in data (value in this case) to the function
- host.Call(typeof(Functions).GetMethod("ManualTrigger"), new { value = 20 });
- host.RunAndBlock();
- }
- }
- public class Functions
- {
- private readonly ISystemClient _systemClient;
- public Functions(ISystemClient systemClient)
- {
- _systemClient = systemClient;
- }
- //Not static anymore
- [NoAutomaticTrigger]
- public void ManualTrigger(TextWriter log, int value, [Queue("queue")] out string message)
- {
- log.WriteLine("Function is invoked with value={0}", value);
- message = value.ToString();
- log.WriteLine("username:{0} and password:{1}", _systemClient.UserName, _systemClient.PassWord);
- }
- }
- Found the following functions:
- TestWebJob.Functions.ManualTrigger
- Executing 'Functions.ManualTrigger' (Reason='This function was programmatically called via the host APIs.', Id=bf9aedc0-89d1-4ba0-a33e-9b23e0d7b8a2)
- Function is invoked with value=20
- Following message will be written on the Queue=20
- username:admin and password:admin1234
- Executed 'Functions.ManualTrigger' (Succeeded, Id=bf9aedc0-89d1-4ba0-a33e-9b23e0d7b8a2)
- Job host started
Add Comment
Please, Sign In to add comment