C
C#

help

Interface that is implemented to multiple classes (different types of objects)

Rreeeeeee9/22/2022
Method in class1:
public Employee CreateEmployee(EmployeeCreateModel1 model) { .... }
public Employee CreateEmployee(EmployeeCreateModel1 model) { .... }
Method in class2:
public Employee CreateEmployee(EmployeeCreateModel2 model) { .... }
public Employee CreateEmployee(EmployeeCreateModel2 model) { .... }
How could I create interface that would be used for both of them..
public interface EmployeeService {
Employee CreateEmployee(??? createmodel);
}
public interface EmployeeService {
Employee CreateEmployee(??? createmodel);
}
Any idea/advice?
YYawnder9/22/2022
That's exactly what an interface is for. You create one that is implemented by multiple classes, and then you specify that that method takes in that interface. @reeeeeee
Rreeeeeee9/22/2022
Yes but how would I specify the input parameter, if each service method expects different type
YYawnder9/22/2022
If you expect a different implementation, then why bother with an interface? An interface is when you don't care about the implementation, as long as it meets some criteria.
Rreeeeeee9/22/2022
I have some kind of a background worker, which uses two kinds of APIs. You specify type of API in the appsettings. The whole processing of the data is completely the same, except some models/DTO.. would be better to always check if type1 -> use service1, elee use service2?
YYawnder9/22/2022
Without seeing the code itself it's hard to say, but yes, you could either do a type switch for that, or explore generics / generic registrations in your DI.
UUUnknown User9/22/2022
Message Not Public
Sign In & Join Server To View

Looking for more? Join the community!

Want results from more Discord servers?
Add your server
Recommended Posts
Wpf how to send custom event (or RoutedEvent) from parent to all childs that implement the handler.Hi guys, as the title says, i want to send an event from parent control to all childrens that impleMinimal API's WithNameWhat does `WithName` do? ```cs app.MapGet("ftx", FtxSubscribe).WithName("FtxUserTradesSubscription"EF Core Global Query Filter ExceptionHi friends, I'm try to create a `Global query filter` for my `EF Core`, to be honest this is the firForeach vs Count with likes tableGuys I made a Vote(likes and dislikes) table. It's similar to reddit's karma system. Dislikes decreadonut.ci wonder where the mistake is in here, i've read over https://www.a1k0n.net/2011/07/20/donut-math.htAccess list when creating an accountI'm creating a login system, I need an access list in it. Who can I allow to log in and who can I reKeep getting infinity output when I dont want that [Answered]My program keeps giving infinity and I'm lost lolHide cmd output when executed from a Console app?I'm brand new to C#, am messinga round with VS -- I'm starting cmd.exe w/ some args with > outputdirPassing the where parameters by the functionHow do I get this sample code to work? Unfortunately, it does not want to work. ```cs public asyError Introducing FOREIGN KEY constraint``` An error occurred while accessing the Microsoft.Extensions.Hosting services. Continuing without lc.exe exited with code -1I was creating my project with bunifu ui I went to uninstall the package from bunifu ui and now it kRun Method on other thread and call method on main thread after it finishedI have this code and want to execute everything after t.Start() as soon as it finished but without bCreate regex that returns the match onlyI have this regex and I want to only get whats inside after the --output in the string (without quotMultiple types in a params without casting?Feel like I'm hoping for an unrealistic expectation, but is it possible to have multiple types in a [XUnit, Moq, EFCore] Unit Testing QuestionHi folks, needing some advice on this approach. This is my first real go at unit testing, so wanted Azure function returning errorHere is the error I get from the Azure function test: ```2022-09-21T14:04:51.850 [Error] Executed 'MA way to get an integer input quickly?Recently i'm trying to do competitive programming with C# and i'm curious if there's a way to get anHow to keep track of third property in Many-To-ManyI have 2 models one that is Reservation and one that is Menu, They have a many-to-many relation but loopplease help me outEF Core Global Query Filter with Nullable ExceptionHi friends, I'm try to create a `Global query filter` for my `EF Core`, to be honest this is the fir