---Presenter: Eric WeathersSubject: How To Deal with Work-Arounds and Common Work-Arounds Needed in ConnectDuration: 00:15:59---00:00:05.000 --> 00:00:10.220 - By the way, we want to do this is, let's say, and I'll kind of 00:00:10.220 --> 00:00:13.700 - run through a very, very base of very basic one. 00:00:14.500 --> 00:00:19.060 - But let's say we wanted to add a new ERP to this. So for example, 00:00:19.060 --> 00:00:23.012 - we had this training connector, but we wanted to add 1 for some 00:00:23.012 --> 00:00:26.356 - some payment provider. Let's say we needed to integrate with the 00:00:26.356 --> 00:00:29.396 - payment provider. So the first thing we want to do. 00:00:29.560 --> 00:00:33.564 - And give me a second. I'm sorry if I forget a couple things. 00:00:33.564 --> 00:00:37.568 - It's been a little while since I've done this, but OK. So the 00:00:37.568 --> 00:00:41.880 - first thing we want to do is we need to create the class. The 00:00:41.880 --> 00:00:45.268 - interfaces in the controllers so we have our inner interfaces. We 00:00:45.268 --> 00:00:48.656 - would add a new interface and let's just call this I. 00:00:49.220 --> 00:00:53.240 - Payments service 00:00:55.270 --> 00:00:59.330 - Payments. Yes, payment services. 00:01:01.030 --> 00:01:05.240 - OK, and this is going to be a public interface. 00:01:07.840 --> 00:01:11.560 - OK, and then we're going to create the actual service 00:01:11.560 --> 00:01:14.164 - itself, so we're going to add a 00:01:14.164 --> 00:01:19.108 - new item. We're going to call this the payment surface. 00:01:22.890 --> 00:01:25.658 - And actually, we're going to pull it out. 00:01:27.340 --> 00:01:28.890 - OK, so. 00:01:30.860 --> 00:01:34.853 - Let's let's say within this this and then this training or 00:01:34.853 --> 00:01:39.209 - payment service we need to go get a specific payment. So we 00:01:39.209 --> 00:01:46.458 - would say. So we would want to do a oops. 00:01:47.730 --> 00:01:51.906 - Task of let's just say object for now because. 00:01:52.920 --> 00:01:59.173 - I don't have any classes made up, but a task of objects and 00:01:59.173 --> 00:02:02.059 - let's say this would be a. 00:02:03.120 --> 00:02:04.200 - Read. 00:02:05.580 --> 00:02:08.790 - Payment service payments. 00:02:09.450 --> 00:02:13.060 - Payment service 00:02:13.060 --> 00:02:18.930 - payment the. Naming convention is the action 00:02:18.930 --> 00:02:22.310 - you're doing. The ERP that you're working through it. So 00:02:22.310 --> 00:02:26.366 - for example, if we were working with Seth, we'd say read Seth, 00:02:26.366 --> 00:02:30.422 - then the entity and then and then any kind of extra value 00:02:30.422 --> 00:02:35.154 - should put on here. So for example, if we did it by ID, who 00:02:35.154 --> 00:02:40.224 - would put by ID on the end of that? And then let's say we take 00:02:40.224 --> 00:02:43.604 - in and into the ID, and probably a cancellation token. 00:02:47.790 --> 00:02:48.490 - Tokens. 00:02:49.880 --> 00:02:54.469 - OK, so next thing we do is we need to implement this I 00:02:54.469 --> 00:02:57.646 - payment service into our payment service. So we will 00:02:57.646 --> 00:02:59.411 - do our I payment service. 00:03:00.510 --> 00:03:02.070 - And we will. 00:03:05.640 --> 00:03:06.858 - Implement the interface. 00:03:07.360 --> 00:03:09.144 - And this needs to be in a sink. 00:03:10.790 --> 00:03:14.498 - OK, so right now we're just going to the throne. Not new. 00:03:14.498 --> 00:03:17.897 - Not implemented, but at this point you would call. You would 00:03:17.897 --> 00:03:20.987 - create your requests in your request handlers up here. And 00:03:20.987 --> 00:03:24.386 - basically you would call those. So let's look at the eye 00:03:24.386 --> 00:03:27.476 - training service for example. So the eye training service has 00:03:27.476 --> 00:03:30.566 - list training product, San retraining product. But if we go 00:03:30.566 --> 00:03:34.274 - to the training service, here is where it calls all of the 00:03:34.274 --> 00:03:37.055 - mediator send, which ends up calling the request request 00:03:37.055 --> 00:03:40.924 - handlers. But this is just a basic way too. 00:03:41.560 --> 00:03:42.730 - 2 00:03:43.930 --> 00:03:50.422 - Separate the this out. So for example where we call, this is 00:03:50.422 --> 00:03:54.856 - here. Instead of calling mediator dot send and have all 00:03:54.856 --> 00:03:59.328 - these other things, we basically pass what we need it and then it 00:03:59.328 --> 00:04:02.424 - handles doing the mediator dots and creating the new. 00:04:03.550 --> 00:04:08.710 - Creating the new request type and then passing it in. So we're 00:04:08.710 --> 00:04:13.440 - basically just separating things out. OK, so from there now we 00:04:13.440 --> 00:04:16.230 - have our. Payment service 00:04:17.220 --> 00:04:21.120 - But now we need to be able to use it. So for 00:04:21.120 --> 00:04:22.420 - example, if I have. 00:04:23.440 --> 00:04:24.600 - See. 00:04:25.690 --> 00:04:28.039 - Where is my? 00:04:28.620 --> 00:04:31.290 - Nope, job service, so for example. 00:04:32.510 --> 00:04:36.917 - I need to use in this partial class of job service. So let's 00:04:36.917 --> 00:04:41.324 - say my product controller. I need to somehow do a any I need 00:04:41.324 --> 00:04:45.392 - to go look for a specific payment and it wouldn't be a 00:04:45.392 --> 00:04:48.782 - product, so obviously probably more on sales orders but but 00:04:48.782 --> 00:04:52.850 - just for the sake of talking about this, we would need to 00:04:52.850 --> 00:04:54.545 - know the payment value here. 00:04:54.550 --> 00:04:58.345 - We would need to have this payment service available to us. 00:04:58.345 --> 00:05:03.175 - Well, I can't. Just I don't want to just new up a payment service 00:05:03.175 --> 00:05:06.280 - because basically that kind of breaks our dependency injection. 00:05:06.280 --> 00:05:09.040 - So what I need is I need a. 00:05:09.740 --> 00:05:13.623 - An instance of the payment service given to me inside of 00:05:13.623 --> 00:05:18.212 - this instance of my job service class. So the way we're going to 00:05:18.212 --> 00:05:22.448 - do that is we're going to inject it into the startup services. 00:05:23.480 --> 00:05:28.550 - So we're going to do connect services, so in here and you can 00:05:28.550 --> 00:05:32.450 - kind of see some examples here. We're going to add. 00:05:33.460 --> 00:05:38.036 - We're going to add that service in here, so we're going to add 00:05:38.036 --> 00:05:43.323 - scoped. And there are three lifetimes for for your services. 00:05:43.323 --> 00:05:47.436 - You have scoped transient and you have Singleton. Basically, 00:05:47.436 --> 00:05:52.463 - Singleton means that you get one instance of it throughout the 00:05:52.463 --> 00:05:53.834 - entire application it. 00:05:53.860 --> 00:05:57.832 - Initiates at once, and that's the one you get. Scoped is a 00:05:57.832 --> 00:06:02.135 - little bit little bit longer or a little bit shorter of a life 00:06:02.135 --> 00:06:06.107 - span, so where you have one instance of it wherever you are 00:06:06.107 --> 00:06:10.079 - creating it. So for example, if I like this, I training service 00:06:10.079 --> 00:06:14.382 - is a scope training service, so if I go to my product controller 00:06:14.382 --> 00:06:18.354 - I'm using training service here, so anywhere that I would use it 00:06:18.354 --> 00:06:21.664 - within this one instance, I'm getting the same, the same 00:06:21.664 --> 00:06:24.643 - instance of that training service. The last one is 00:06:24.643 --> 00:06:27.209 - transient. And transient initializes a new one every 00:06:27.209 --> 00:06:31.013 - single time you call it. So for example here if this was 00:06:31.013 --> 00:06:34.500 - transient, I get an instance of training service here, and then 00:06:34.500 --> 00:06:37.353 - I get us completely separate instance of training service 00:06:37.353 --> 00:06:41.474 - here. If I called it 4 lines down, I get another one there, 00:06:41.474 --> 00:06:44.961 - so it's a different way to use life lifetimes and disposing 00:06:44.961 --> 00:06:47.814 - things in different in different scenarios. So not necessarily 00:06:47.814 --> 00:06:51.935 - what this video is over, but a good little caveat there. So the 00:06:51.935 --> 00:06:55.422 - first thing we're gonna do is what you're adding is you're 00:06:55.422 --> 00:07:00.322 - adding an instance. Of the interface, so our interfaces I 00:07:00.322 --> 00:07:04.770 - payment service and the instance is payment service. 00:07:08.450 --> 00:07:10.790 - So this is where. 00:07:11.370 --> 00:07:13.834 - You might, let's see what's our issue. 00:07:17.180 --> 00:07:20.638 - And this is kind of good for the video to you, let's see. 00:07:22.000 --> 00:07:24.178 - Clarity dot shared. 00:07:24.980 --> 00:07:25.940 - Did I? 00:07:28.240 --> 00:07:30.664 - Yeah, I think I just need to be 00:07:30.664 --> 00:07:32.340 - services. Yep. 00:07:33.500 --> 00:07:37.556 - So because I put this in a folder, it added this dot 00:07:37.556 --> 00:07:41.274 - interfaces onto my name space and I'm using basically the same 00:07:41.274 --> 00:07:43.978 - namespace of Justice, clarity, connect services throughout. So 00:07:43.978 --> 00:07:48.372 - I need to come in here and reduce this down. So just that 00:07:48.372 --> 00:07:52.428 - same thing with this one because initially I put in this folder, 00:07:52.428 --> 00:07:55.470 - make sure that all your namespaces are the same. 00:07:56.310 --> 00:07:59.766 - So that should clean up this. If not, let's 00:07:59.766 --> 00:08:01.302 - see what happens type. 00:08:02.620 --> 00:08:09.706 - So let's go back to our 00:08:09.706 --> 00:08:16.792 - start class. Can you hear me? 00:08:16.800 --> 00:08:22.152 - And then let's go back to our connect services and then we 00:08:22.152 --> 00:08:25.274 - added this payment service. Didn't like that. 00:08:25.790 --> 00:08:28.672 - So see what her issue is now. Cyber new cities payment 00:08:28.672 --> 00:08:29.720 - service can't be found. 00:08:36.900 --> 00:08:37.430 - Whoops 00:08:40.500 --> 00:08:47.846 - It's weird. Did not save. I didn't say 00:08:47.846 --> 00:08:48.707 - that. 00:08:51.730 --> 00:08:55.290 - OK, I'll go make this real quick again. 00:08:57.080 --> 00:08:58.859 - And I will. 00:09:01.870 --> 00:09:13.810 - Class. 00:09:15.290 --> 00:09:18.458 - Monthly I payments service. 00:09:19.550 --> 00:09:26.634 - OK, save that and now won't go back to start up. 00:09:30.760 --> 00:09:33.370 - Alright, What don't you like this time type clearly connect 00:09:33.370 --> 00:09:34.675 - payment service company uses a 00:09:34.675 --> 00:09:39.960 - type parameter. Is generic type of method at scope to service to 00:09:39.960 --> 00:09:43.328 - Penn Station I service collection. There's no implicit 00:09:43.328 --> 00:09:44.591 - reference conversion from 00:09:44.591 --> 00:09:47.999 - payment service. I payment service. 00:09:49.720 --> 00:09:50.700 - How? 00:10:12.610 --> 00:10:15.558 - Oh, is there another payment service in here? There must be 00:10:15.558 --> 00:10:18.238 - another payment service in this quality dot shared, so that's 00:10:18.238 --> 00:10:22.206 - kind of A. A1 off let me see if I change the name of this if 00:10:22.206 --> 00:10:25.868 - that'll. I test payment service. 00:10:26.830 --> 00:10:28.170 - Man. 00:10:33.650 --> 00:10:41.094 - Test. Then we'll go back 00:10:41.094 --> 00:10:44.578 - to our service extensions. 00:10:47.710 --> 00:10:51.290 - It doesn't like that still type such as type parameter 00:10:51.290 --> 00:10:53.796 - team to tation. There's no implicit reference. 00:10:55.140 --> 00:11:01.743 - Oh. There we go. So yeah, it was just. It was just a name 00:11:01.743 --> 00:11:04.200 - naming confliction between something else. So definitely 00:11:04.200 --> 00:11:07.008 - something to watch out for. Basically just like. 00:11:07.560 --> 00:11:11.927 - In that in this case, just reading the error that you're 00:11:11.927 --> 00:11:15.750 - getting. And you know, I've seen that error before, so I was able 00:11:15.750 --> 00:11:19.455 - to do it, but otherwise you might have to like Google it or 00:11:19.455 --> 00:11:23.820 - just check the. You know, when I did like the I payment service, 00:11:23.820 --> 00:11:25.204 - I checked like the. 00:11:25.210 --> 00:11:29.731 - There are some suggestions and just looking at those and seeing 00:11:29.731 --> 00:11:31.786 - OK, there's a basically added. 00:11:32.420 --> 00:11:36.308 - Us the full name of the 00:11:36.308 --> 00:11:41.160 - of the. Value at that point. It's like OK, well, because it 00:11:41.160 --> 00:11:44.108 - added a full name. That means somewhere else that's trying to 00:11:44.108 --> 00:11:47.324 - reference the same name, so it has to depict which one is 00:11:47.324 --> 00:11:51.076 - which. So it's kind of it's kind of like I said, this kind of 00:11:51.076 --> 00:11:54.292 - stuff, but hopefully in the call or hopefully in the video you 00:11:54.292 --> 00:11:58.580 - can kind of edit it and make it good on that, but OK. So now we 00:11:58.580 --> 00:12:00.188 - have it added to our services 00:12:00.188 --> 00:12:04.758 - container. And what that allows us to do is anywhere we have a 00:12:04.758 --> 00:12:08.406 - constructor. We can pass this value in. So for example, on our 00:12:08.406 --> 00:12:12.747 - job service now. I can OK, why are you not? 00:12:15.540 --> 00:12:19.372 - Let's see public partial class job service process 00:12:19.372 --> 00:12:23.683 - product should have OK. Why don't you exist anymore? 00:12:26.680 --> 00:12:27.980 - It doesn't make any sense. 00:12:29.010 --> 00:12:33.385 - I think this is a problem with. 00:12:38.300 --> 00:12:40.820 - My computer shutting down like that. 00:12:42.140 --> 00:12:45.660 - Either way, let's let's. 00:12:47.620 --> 00:12:50.100 - I guess go created here real quick will just do 00:12:50.100 --> 00:12:51.340 - it here just for the. 00:12:52.760 --> 00:12:57.002 - Just for ease of it, you know he's but OK, so let's say we 00:12:57.002 --> 00:13:00.335 - need to use this payment service inside this process product for 00:13:00.335 --> 00:13:03.668 - one of our hang fire jobs. So what we would do? 00:13:04.410 --> 00:13:08.142 - As we need to inject it into constructor so the first thing 00:13:08.142 --> 00:13:12.807 - we do is we need to create a read only version of it. So we 00:13:12.807 --> 00:13:16.228 - would say private readonly. I test payment service and then we 00:13:16.228 --> 00:13:19.027 - name it like underscore test payment service because it's 00:13:19.027 --> 00:13:22.759 - read only for a read only variable. Those can only be set 00:13:22.759 --> 00:13:26.180 - in the constructors or right here. But because we don't have 00:13:26.180 --> 00:13:30.223 - we don't have the instance of it yet. We need we need to 00:13:30.223 --> 00:13:33.022 - instantiate it in the constructor. So we're going to 00:13:33.022 --> 00:13:34.577 - pass that in as a. 00:13:34.630 --> 00:13:39.697 - Value here I test payment service test payment service. 00:13:40.920 --> 00:13:45.144 - And then we're going to set this readonly value that I have 00:13:45.144 --> 00:13:49.016 - access to everywhere. So the value is getting passed into the 00:13:49.016 --> 00:13:52.888 - constructor, so the last step is to say says payment service 00:13:52.888 --> 00:13:54.296 - equals test payment service. 00:13:55.120 --> 00:13:59.170 - And now I can use it River so I can say in my process product. 00:13:59.170 --> 00:14:00.790 - So I need to go get. 00:14:02.450 --> 00:14:06.623 - I need to call my read payment service by ID and let's just 00:14:06.623 --> 00:14:09.191 - make up an ID and give it my 00:14:09.191 --> 00:14:14.680 - token. And because this is actually I didn't make it, but 00:14:14.680 --> 00:14:17.446 - is supposed to be a sink. 00:14:20.320 --> 00:14:25.888 - I can call my bar payment equals awaits. 00:14:27.370 --> 00:14:32.519 - And configure. So it's kind of a couple let's 00:14:32.519 --> 00:14:35.189 - see why don't you do like this needs to be? 00:14:37.250 --> 00:14:41.287 - That's kind of, you know, a couple a couple debugging steps 00:14:41.287 --> 00:14:44.957 - along the way of adding a service into the constructor. 00:14:44.957 --> 00:14:48.627 - Obviously there's plenty of other things I'm sure that could 00:14:48.627 --> 00:14:53.398 - go wrong if you're not doing it exactly right, but if we sat 00:14:53.398 --> 00:14:57.802 - here and tried to think of every single possible way we'd be 00:14:57.802 --> 00:15:00.004 - sitting here for the next couple 00:15:00.004 --> 00:15:04.340 - hours so. You know, ultimately, hopefully you know anyone who's 00:15:04.340 --> 00:15:07.940 - running into this problem. Can problem solve a little bit? 00:15:07.940 --> 00:15:11.540 - There's plenty of documentation out there in terms of adding 00:15:11.540 --> 00:15:15.500 - adding to the services container on a.net core project, and I'm 00:15:15.500 --> 00:15:19.820 - sure it's not whatever issue comes up is not the first time, 00:15:19.820 --> 00:15:23.780 - so stackoverflow just regular Google should be able to come up 00:15:23.780 --> 00:15:27.740 - with, you know at least most most errors and then just 00:15:27.740 --> 00:15:31.340 - recommend that anyone who comes across an error having trouble, 00:15:31.340 --> 00:15:34.950 - you know. Injecting something into the di container that they 00:15:34.950 --> 00:15:38.855 - added to our internal stack overflow as well just for any 00:15:38.855 --> 00:15:42.405 - issues so that we have that internal documentation too. But 00:15:42.405 --> 00:15:45.600 - but basically that's that's a quick quick little creative 00:15:45.600 --> 00:15:48.795 - training service or creating a creative service. Create the 00:15:48.795 --> 00:15:52.345 - interface and add it to the services container. An injected 00:15:52.345 --> 00:15:56.960 - into constructor so you can use it, but I think that's kind of 00:15:56.960 --> 00:15:58.380 - it for that one.