Код: Выделить всё
net8.0
enable
enable
Linux
..\docker-compose.dcproj
Код: Выделить всё
public static void ConfigureServices(this IServiceCollection services)
{
// TODO: Get all project references as an array to optimize below code.
var serviceTypes = Assembly.GetExecutingAssembly().GetTypes();
var idTypes = Assembly.Load("Identity").GetTypes();
var txTypes = Assembly.Load("Transaction").GetTypes();
serviceTypes = serviceTypes.Concat(idTypes).Concat(txTypes).ToArray()
.Where(t => typeof(IService).IsAssignableFrom(t) && !t.IsInterface && !t.IsAbstract)
.ToArray();
foreach (var serviceType in serviceTypes)
{
var interfaceType = serviceType.GetInterfaces()
.FirstOrDefault(i => typeof(IService).IsAssignableFrom(i));
if (interfaceType != null)
{
services.AddScoped(interfaceType, serviceType);
}
}
}
Код: Выделить всё
// Common library
public interface IService
{
}
// Identity library
public interface IUserService : IService {
}
public class UserService : IUserService {
}
// Transaction library
public interface ITransactionService : IService {
}
public class TransactionService : ITransactionService {
}
Подробнее здесь: https://stackoverflow.com/questions/791 ... startup-cs
Мобильная версия