CSharp · Console
using System;
using System.Threading.Tasks;
public class Program
{
public static async Task Main()
{
var test = new Test();
await test.UpdateUserStatus(1, 2);
}
}
public sealed class Test
{
public async Task UpdateStatus<TService, T>(int id, int status, Func<TService> serviceCreator)
where TService : StatusService<T>
{
await serviceCreator().UpdateStatus(id, status);
}
public async Task UpdateUserStatus(int id, int status)
{
var context = new MyContext(); // However you obtain this.
await UpdateStatus<UserService, User>(id, status, () => new UserService(context));
}
}
public abstract class StatusService<T>
{
protected StatusService(MyContext context)
{
Console.Write("StatusService<T> constructor called for type " + typeof(T).FullName);
}
public abstract Task UpdateStatus(int id, int status);
}
public class UserService : StatusService<User>
{
public UserService(MyContext context) : base(context)
{
}
public override async Task UpdateStatus(int id, int status)
{
await Task.Delay(0);
}
}
public class MyContext
{
}
public class User
{
}