Heres my issue. I have different types of methods which make HTTP requests to a REST api. To keep things clean, I have methods that take different types of request objects as parameters. Example below.
Task<IEventResponse> FindEventAsync(IGetEventsRequest data, CancellationToken token);
So everytime my controller calls this method, it has to create a object of type IGetEventsRequest. Creating a new() instance of its implementation feels dumb, and I started thinking about creating a generic factory which could create these objects for me, and also work for all kinds of object types. Any help how could I achieve this?
I am looking for this kind of syntax:
await FindEventsAsync(_requestFactory.Create(?somehow specify the type of this and generate a new object based on the type), CancelationToken.None);