如果不考虑第三方库,如Autofac这种进行服务注入,通过本身的.Core Weabpi实现的,总结了两种实现方法,
1.一种是参考abp框架里面的形式;
1.1 新建个生命周期的文件夹:
三个接口分别为:
public interface IScopedDependency
{
}
public interface ISingletonDependency
{
}
public interface ITransientDependency
{
}
在实现类中使用如下:
public interface IUserService
{
}
public class UserService : IUserService, ITransientDependency
{
}
1.2 建立个批量服务注册的扩展方法:
public static class ConfigSservice
{
public static void BatchAddServices(this IServiceCollection services, string assemblyString)
{
var assembly = Assembly.Load(assemblyString);
var types = assembly.GetTypes();
var lis