---Presenter: Eric WeatherSubject: OptionsDuration: 00:11:00---00:00:05.740 --> 00:00:09.580 - In this video, we're going to be talking about how to utilize 00:00:09.580 --> 00:00:12.460 - options both for a connector integration service for the 00:00:12.460 --> 00:00:15.660 - options for like the HTTP client, and then we're also 00:00:15.660 --> 00:00:20.140 - going to set an options for our job service and show how to pull 00:00:20.140 --> 00:00:23.340 - values out into settings that can be injected wherever you 00:00:23.340 --> 00:00:27.500 - need them. So the first thing to start off with, we're going to 00:00:27.500 --> 00:00:31.660 - start with our connector and how to set those options up so the 00:00:31.660 --> 00:00:35.180 - first thing we're going to look at is in our options. 00:00:35.890 --> 00:00:39.160 - Are I'm sorry in our training connector options you should 00:00:39.160 --> 00:00:42.430 - have the and I say training connector training is our 00:00:42.430 --> 00:00:46.354 - example here, so this could be CRM's F. This could be NetSuite 00:00:46.354 --> 00:00:49.951 - whatever it is connector and then that would say the same 00:00:49.951 --> 00:00:53.875 - thing options. So we're going to open up our options. This is 00:00:53.875 --> 00:00:55.837 - going to be a public class. 00:00:56.720 --> 00:01:00.815 - So this is we're just we're going to add we're going to add 00:01:00.815 --> 00:01:04.280 - properties here. So the first thing we know we need for 00:01:04.280 --> 00:01:08.060 - training for the training API, and this is going to change. So 00:01:08.060 --> 00:01:11.840 - whatever you might need, and this is we're going to put your 00:01:11.840 --> 00:01:14.990 - username, your password, your token ID if you're using token 00:01:14.990 --> 00:01:17.825 - based authentication, any client ID client secrets, any other 00:01:17.825 --> 00:01:21.290 - information you would need to give to the to the ERP 00:01:21.290 --> 00:01:24.440 - integration service so that it can instantiate any kind of 00:01:24.440 --> 00:01:26.015 - connection it needs, whether it 00:01:26.015 --> 00:01:30.112 - be soap. Rest whatever, So what we need for the training Web API 00:01:30.112 --> 00:01:34.340 - is at this time only a base URL, so we're going to create a 00:01:34.340 --> 00:01:37.662 - public string. We're just going to call this URL, but we're 00:01:37.662 --> 00:01:41.890 - going to add two more just so that we can see how that works. 00:01:41.890 --> 00:01:45.514 - So we're going to add a public string of a user name. 00:01:47.010 --> 00:01:50.299 - And we're going to add a public string of a password. 00:01:51.690 --> 00:01:56.431 - OK. So now we have both of these values, so the first thing that 00:01:56.431 --> 00:01:58.230 - we're going to do is we're going 00:01:58.230 --> 00:02:02.630 - to create. This object in our app settings so that we can 00:02:02.630 --> 00:02:06.227 - utilize these things. So we're going to open up our base 00:02:06.227 --> 00:02:09.824 - project here and we're going to go to app settings, development, 00:02:09.824 --> 00:02:12.767 - development, Jason and we're going to create a new. 00:02:14.290 --> 00:02:19.750 - A new section here we're going to call this sorry we're going 00:02:19.750 --> 00:02:21.570 - to call this training. 00:02:22.650 --> 00:02:24.350 - Training options. 00:02:27.200 --> 00:02:29.258 - The first value that we had was 00:02:29.258 --> 00:02:33.144 - the URL. So that value is 00:02:33.144 --> 00:02:36.160 - localhost. 4 four loops. 00:02:40.620 --> 00:02:45.338 - 4435 and then it was slash API. 00:02:48.420 --> 00:02:49.788 - Lower case API. 00:02:50.650 --> 00:02:52.540 - And then we had an HTTPS in 00:02:52.540 --> 00:02:58.484 - front of it. OK, so now we have our URL. Let's go ahead and do 00:02:58.484 --> 00:03:02.466 - our other ones so we're not using it currently, but let's 00:03:02.466 --> 00:03:06.810 - just say we were using username password so will say clarity and 00:03:06.810 --> 00:03:08.258 - then our password here. 00:03:09.250 --> 00:03:15.476 - Who's going to be our super super secretive P4SS WORD? Don't 00:03:15.476 --> 00:03:20.004 - tell anybody, never using that password. Alright so. 00:03:20.710 --> 00:03:24.178 - We're going to save that now. We can inject it into our 00:03:24.178 --> 00:03:26.779 - services. So now we look at our service extension. 00:03:27.840 --> 00:03:31.620 - And we're going to go to our options extension. So in our 00:03:31.620 --> 00:03:35.400 - options, just like you can see here, we're going to use this 00:03:35.400 --> 00:03:39.180 - same structure, so we're going to give it to our services, so 00:03:39.180 --> 00:03:41.070 - we're going to say services dot. 00:03:42.640 --> 00:03:45.130 - Dot configure. 00:03:46.350 --> 00:03:49.239 - This is going to be of type training options. 00:03:50.640 --> 00:03:53.040 - We're going to have to add a reference here if you're using 00:03:53.040 --> 00:03:55.040 - a new get package, you obviously add the reference to 00:03:55.040 --> 00:03:57.240 - the new get package. We're using a project at the moment, 00:03:57.240 --> 00:03:58.640 - so we're going to do are using. 00:04:00.310 --> 00:04:03.973 - Then we're going to grab our configuration that we gave to 00:04:03.973 --> 00:04:06.637 - ourselves in the service collection dot git section. 00:04:07.670 --> 00:04:11.040 - And we're getting the section with the name of training 00:04:11.040 --> 00:04:14.747 - options because that is what we tiled titled it right here. 00:04:15.890 --> 00:04:17.897 - So it's going to grab all of these values. 00:04:19.520 --> 00:04:22.340 - And Deserialize it into a training options class, which is 00:04:22.340 --> 00:04:24.032 - what we set up right here. 00:04:26.460 --> 00:04:30.217 - And that's it. So if we go over to our integration services, you 00:04:30.217 --> 00:04:33.396 - can see that we have we're injecting this into what we 00:04:33.396 --> 00:04:37.153 - haven't gotten to set. Setting to set up, but at least in one 00:04:37.153 --> 00:04:40.043 - of these constructors, or the constructor that we end up 00:04:40.043 --> 00:04:42.933 - using, we have our training options that were giving to 00:04:42.933 --> 00:04:46.690 - ourselves. If we need him, it's possible that we only need it in 00:04:46.690 --> 00:04:48.713 - the configuration of the training integration service 00:04:48.713 --> 00:04:52.181 - itself, but at the moment that's all we're going to need, so 00:04:52.181 --> 00:04:55.649 - let's we'll go over how to use that when setting this up. 00:04:55.649 --> 00:04:57.383 - Adding the HTTP client for this 00:04:57.383 --> 00:05:01.236 - later. In a different video, but for now we're good here. OK, so 00:05:01.236 --> 00:05:04.785 - the next set of options that we're going to set up are ones 00:05:04.785 --> 00:05:08.061 - that were going to pull values out into app settings from, say, 00:05:08.061 --> 00:05:11.337 - our job service that we want to inject later so that customers 00:05:11.337 --> 00:05:14.613 - or clients can change them at the app setting level and just 00:05:14.613 --> 00:05:18.162 - reset the app pool rather than having to go into the code and 00:05:18.162 --> 00:05:21.165 - manually change these things. So the baseline that we're going to 00:05:21.165 --> 00:05:22.257 - use for an example. 00:05:23.240 --> 00:05:26.564 - We're going to do our job service and we want this value 00:05:26.564 --> 00:05:30.385 - right here. To be pulled out into a setting we don't want to 00:05:30.385 --> 00:05:32.970 - have this type because if they have, let's say, started running 00:05:32.970 --> 00:05:36.025 - every 15 minutes and they want to take that down to every 5 00:05:36.025 --> 00:05:39.080 - minutes, we don't want to have to come in here and change this 00:05:39.080 --> 00:05:41.900 - value in the code and then redeploy. We just want to pull 00:05:41.900 --> 00:05:44.955 - this out into a setting, reset the app pool and there on there 00:05:44.955 --> 00:05:48.010 - way. So the first thing we're going to do is we're going to 00:05:48.010 --> 00:05:50.125 - create that options in our clarity connect options. So 00:05:50.125 --> 00:05:55.262 - we're going to add. A new item. It's going to be a 00:05:55.262 --> 00:05:59.213 - class, and we're going to call this Cron settings. 00:06:02.580 --> 00:06:05.388 - OK, so we're going to make this a public class and you 00:06:05.388 --> 00:06:07.494 - can call this whatever. I'm just calling it Crown 00:06:07.494 --> 00:06:07.728 - settings. 00:06:09.930 --> 00:06:13.999 - But for example, our job service uses at the moment test job, so 00:06:13.999 --> 00:06:18.068 - that's what that's what I'm going to do it based on. So I 00:06:18.068 --> 00:06:22.137 - have a test job, so I'm going to call this test job Cron. 00:06:23.060 --> 00:06:24.971 - This is going to be a public 00:06:24.971 --> 00:06:27.808 - string. Anne will put our gitter inside around here. 00:06:29.780 --> 00:06:33.716 - OK, very simple. Nothing hard about it. We're going to go to 00:06:33.716 --> 00:06:36.996 - our app settings development again. We're going to create a 00:06:36.996 --> 00:06:39.948 - new object. We're going to call it Cron settings. 00:06:42.810 --> 00:06:46.289 - And then we had test job Cron. 00:06:47.660 --> 00:06:51.840 - And the value here we're going to do of star. 00:06:52.990 --> 00:06:54.190 - We're going to do this every 00:06:54.190 --> 00:06:59.150 - five minutes, let's say. 1234 and five. 00:07:00.290 --> 00:07:03.602 - And now we have it ready to inject. So now we're going 00:07:03.602 --> 00:07:05.534 - to back. Remember to our options extensions. 00:07:07.440 --> 00:07:10.190 - And we're going to add it very similar to this 00:07:10.190 --> 00:07:12.665 - because we need to add it to our services 00:07:12.665 --> 00:07:14.865 - configuration. So we're going to configure this is 00:07:14.865 --> 00:07:16.240 - going to be of type. 00:07:17.510 --> 00:07:19.049 - For Cron settings. 00:07:20.920 --> 00:07:23.920 - When you going to add our reference to clarity connect 00:07:23.920 --> 00:07:28.210 - options. And then we're going to do a configuration 00:07:28.210 --> 00:07:29.365 - dot git section. 00:07:30.450 --> 00:07:34.566 - With a name of Cron settings. 00:07:37.050 --> 00:07:41.758 - OK, where it's different between here and here is that our 00:07:41.758 --> 00:07:45.610 - training options. We're probably not going to use later. 00:07:47.510 --> 00:07:52.228 - We're not going to use it here. Most likely we will just use it 00:07:52.228 --> 00:07:55.935 - in our services extension or I'm sorry our HTTP extensions. When 00:07:55.935 --> 00:07:59.979 - we add our extensions you see how we're doing bar options dot 00:07:59.979 --> 00:08:03.012 - equals speed kit required service of our self options. 00:08:04.200 --> 00:08:07.836 - We're going to be using that there if, for instance, we do 00:08:07.836 --> 00:08:10.563 - need to inject this into our training integration service 00:08:10.563 --> 00:08:14.805 - service, then we will need to do this second step for this one as 00:08:14.805 --> 00:08:18.441 - well. At the moment, we're not doing that, but remember that if 00:08:18.441 --> 00:08:22.380 - you do need to get these options here rather than just at this 00:08:22.380 --> 00:08:25.410 - level, the HTTP extensions level, you'll have to do this 00:08:25.410 --> 00:08:29.652 - for the second one. So the way we're going to do that is we're 00:08:29.652 --> 00:08:32.682 - going to do and dot add Singleton because we're only 00:08:32.682 --> 00:08:34.197 - adding one instance of this. 00:08:34.520 --> 00:08:38.040 - Setting everywhere so only one instance is going to be created 00:08:38.040 --> 00:08:41.560 - for the entire app, so we're going to do a SP. 00:08:42.170 --> 00:08:43.379 - Our service provider. 00:08:44.510 --> 00:08:47.050 - SP dot git required service. 00:08:48.190 --> 00:08:50.269 - This is going to be of type I options. 00:08:51.810 --> 00:08:52.500 - I'm sorry. 00:08:53.930 --> 00:08:56.458 - And we're going to using Microsoft dot extensions 00:08:56.458 --> 00:08:57.090 - dot options. 00:08:58.280 --> 00:09:01.520 - And that is going to be of type Cron settings. 00:09:03.890 --> 00:09:06.618 - That's going to be a dot value because we want the 00:09:06.618 --> 00:09:07.362 - value of that. 00:09:08.410 --> 00:09:12.100 - Configuration OK, so now we have. 00:09:13.220 --> 00:09:16.874 - Basically pulled the values from the configuration and set 00:09:16.874 --> 00:09:20.934 - it into our services and at this point we're actually 00:09:20.934 --> 00:09:24.994 - adding the instance of that setting into into our services 00:09:24.994 --> 00:09:28.648 - container so that it can be injected wherever the 00:09:28.648 --> 00:09:32.302 - Singleton is a single instance were only creating one 00:09:32.302 --> 00:09:35.144 - instance of this. Of this Cron settings. 00:09:36.670 --> 00:09:37.400 - Uh. 00:09:38.760 --> 00:09:39.340 - Class. 00:09:40.780 --> 00:09:43.497 - OK, so now let's go ahead and just show how we're going to 00:09:43.497 --> 00:09:45.796 - inject these Cron settings into our job service and how we're 00:09:45.796 --> 00:09:50.566 - going to use them. So in our constructor we already have our 00:09:50.566 --> 00:09:54.536 - training service. So now we're going to give ourselves a 00:09:54.536 --> 00:09:58.903 - private readonly. This is going to be of type Cron settings. 00:09:59.610 --> 00:10:03.475 - And this is. Going to be loops, we're going to need to add our. 00:10:04.090 --> 00:10:07.186 - Reference this is going to be of Crown settings. 00:10:11.360 --> 00:10:15.273 - OK, now we can put it into our constructor, so we're going to 00:10:15.273 --> 00:10:18.450 - do Cron settings. Crown settings. 00:10:21.250 --> 00:10:26.671 - And then we're going to set it to the read only, so ground 00:10:26.671 --> 00:10:28.339 - settings equals ground settings. 00:10:30.850 --> 00:10:36.240 - OK, now we have access to that to that value. So here we can 00:10:36.240 --> 00:10:40.475 - look at our Cron expression instead of using Cron dot never 00:10:40.475 --> 00:10:45.480 - or chron dot anything. We can do Cron settings dot test job Cron. 00:10:46.290 --> 00:10:49.891 - And we have access to it. So now whatever we change this value 00:10:49.891 --> 00:10:54.932 - to. In our app settings, will be injected into our job service so 00:10:54.932 --> 00:10:56.828 - that we can use it there.