using Autofac; using CommonService; using FishGameService.GameService; using FishGameService.Services; using MongoRepository; namespace FishGameHost.Middleware { public class AutofacModule : Module { protected override void Load(ContainerBuilder builder) { builder.RegisterGeneric(typeof(MongoBaseRepository<>)).As(typeof(IMongoBaseRepository<>)).InstancePerLifetimeScope(); builder.RegisterGeneric(typeof(MongoBaseService<>)).As(typeof(IMongoBaseService<>)).InstancePerLifetimeScope(); builder.RegisterType() .As() .InstancePerLifetimeScope(); builder.RegisterType() .As() .SingleInstance(); builder.RegisterType() .As() .SingleInstance(); builder.RegisterType() .As() .SingleInstance(); builder.RegisterType() .AsSelf() .SingleInstance(); builder.RegisterAssemblyTypes(typeof(ApiLogService).Assembly) .Where(t => t.Name.EndsWith("Service")) .AsImplementedInterfaces() .InstancePerLifetimeScope(); builder.RegisterType() .AsSelf() .As() .SingleInstance(); builder.RegisterAssemblyTypes(typeof(FishingGameService).Assembly) .Where(t => t.Name.EndsWith("Service") && t != typeof(FishSpawnService) && t != typeof(RobotKillAnnounceService)) .AsImplementedInterfaces() .InstancePerLifetimeScope(); builder.RegisterAssemblyTypes(typeof(FishingGameService).Assembly) .Where(t => t.Name.EndsWith("Subscriber")) .AsSelf() .InstancePerLifetimeScope(); builder.RegisterAssemblyTypes(typeof(UserService.User.UserService).Assembly) .Where(t => t.Name.EndsWith("Service")) .AsImplementedInterfaces() .InstancePerLifetimeScope(); } } }