56 lines
1.8 KiB
C#
56 lines
1.8 KiB
C#
using System.Reflection;
|
|
using Autofac;
|
|
using CommonService;
|
|
using MongoRepository;
|
|
using RedisService;
|
|
|
|
namespace SharpAbp.Infrastructure.Api.Autofac
|
|
{
|
|
public abstract class ApplicationModule : global::Autofac.Module
|
|
{
|
|
protected abstract Assembly CurrentAssembly { get; }
|
|
|
|
protected virtual Assembly[] GetServiceAssemblies()
|
|
{
|
|
return new[] { CurrentAssembly };
|
|
}
|
|
|
|
protected virtual bool RegisterMongoBaseService => true;
|
|
|
|
protected override void Load(ContainerBuilder builder)
|
|
{
|
|
builder.RegisterGeneric(typeof(MongoBaseRepository<>))
|
|
.As(typeof(IMongoBaseRepository<>))
|
|
.InstancePerLifetimeScope();
|
|
|
|
if (RegisterMongoBaseService)
|
|
{
|
|
builder.RegisterGeneric(typeof(MongoBaseService<>))
|
|
.As(typeof(IMongoBaseService<>))
|
|
.InstancePerLifetimeScope();
|
|
}
|
|
|
|
builder.RegisterType<RedisService.RedisService>()
|
|
.As<RedisService.IRedisService>()
|
|
.InstancePerLifetimeScope();
|
|
|
|
var serviceAssemblies = GetServiceAssemblies();
|
|
foreach (var assembly in serviceAssemblies)
|
|
{
|
|
builder.RegisterAssemblyTypes(assembly)
|
|
.Where(t => t.Name.EndsWith("Service") && !t.IsAbstract)
|
|
.AsImplementedInterfaces()
|
|
.InstancePerLifetimeScope();
|
|
}
|
|
|
|
foreach (var assembly in serviceAssemblies)
|
|
{
|
|
builder.RegisterAssemblyTypes(assembly)
|
|
.Where(t => t.Name.EndsWith("Repository") && !t.IsAbstract)
|
|
.AsImplementedInterfaces()
|
|
.InstancePerLifetimeScope();
|
|
}
|
|
}
|
|
}
|
|
}
|