public static MSFrameworkBuilder UseEventDispatcher(this MSFrameworkBuilder builder) { var assemblies = AssemblyFinder.GetAllList(); builder.UseEventDispatcher(assemblies.ToArray()); return(builder); }
public static MSFrameworkBuilder UseRequestProcessor(this MSFrameworkBuilder builder) { var assemblies = AssemblyFinder.GetAllList(); builder.UseRequestProcessor(assemblies.ToArray()); return(builder); }
public static MSFrameworkBuilder UseEventDispatcher(this MSFrameworkBuilder builder, params Type[] eventTypes) { var excludeAssembly = typeof(MSFrameworkBuilder).Assembly; var assemblies = eventTypes.Select(x => x.Assembly).ToList(); if (!assemblies.Contains(excludeAssembly)) { assemblies.Add(excludeAssembly); } builder.UseEventDispatcher(assemblies.ToArray()); return(builder); }
public static MSFrameworkBuilder UseRequestProcessor(this MSFrameworkBuilder builder, params Type[] commandTypes) { var excludeAssembly = typeof(MSFrameworkBuilder).Assembly; var assemblies = commandTypes.Select(x => x.Assembly).ToList(); if (!assemblies.Contains(excludeAssembly)) { assemblies.Add(excludeAssembly); } builder.UseRequestProcessor(assemblies.ToArray()); return(builder); }
public static void AddMSFramework(this IServiceCollection services, Action <MSFrameworkBuilder> builderAction = null) { var builder = new MSFrameworkBuilder(services); builderAction?.Invoke(builder); services.AddMemoryCache(); builder.Services.TryAddScoped <IUnitOfWorkManager, DefaultUnitOfWorkManager>(); // 如果你想换成消息队列,则重新注册一个对应的服务即可 builder.Services.TryAddScoped <IAuditService, DefaultAuditService>(); builder.UseInitializer(); }
public static MSFrameworkBuilder AddEventHandlers(this MSFrameworkBuilder builder, params Type[] types) { var handlerType = typeof(IEventHandler); foreach (var type in types) { if (handlerType.IsAssignableFrom(type)) { builder.Services.AddScoped(type, type); } else { throw new Exception("AddCommandHandler"); } } return(builder); }
public static void AddMSFramework(this IServiceCollection services, Action <MSFrameworkBuilder> builderAction = null) { var builder = new MSFrameworkBuilder(services); builderAction?.Invoke(builder); services.AddMemoryCache(); builder.Services.TryAddScoped <IUnitOfWorkManager, DefaultUnitOfWorkManager>(); // 如果你想换成消息队列,则重新注册一个对应的服务即可 builder.Services.TryAddScoped <IAuditService, DefaultAuditService>(); builder.UseInitializer(); var assemblies = AssemblyFinder.GetAllList(); // todo: how to print logs in ConfigureService method Console.WriteLine($"Find assemblies: {string.Join(", ", assemblies.Select(x => x.GetName().Name))}"); }
public static IServiceProvider AddMSFramework(this IServiceCollection services, Action <MSFrameworkBuilder> builderAction = null) { var builder = new MSFrameworkBuilder(services); builderAction?.Invoke(builder); //初始化所有程序集查找器,如需更改程序集查找逻辑,请事先赋予自定义查找器的实例 if (Singleton <IAssemblyFinder> .Instance == null) { Singleton <IAssemblyFinder> .Instance = new AssemblyFinder(); builder.Services.AddSingleton(Singleton <IAssemblyFinder> .Instance); } if (Singleton <IDependencyTypeFinder> .Instance == null) { Singleton <IDependencyTypeFinder> .Instance = new DependencyTypeFinder(); var dependencyTypeDict = Singleton <IDependencyTypeFinder> .Instance.GetDependencyTypeDict(); foreach (var kv in dependencyTypeDict) { builder.Services.Add(kv.Value, kv.Key); } } if (Singleton <IJsonConvert> .Instance == null) { Singleton <IJsonConvert> .Instance = new DefaultJsonConvert(new JsonConvertOptions()); builder.Services.AddSingleton(Singleton <IJsonConvert> .Instance); } builder.Services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); builder.Services.AddScoped <IMSFrameworkSession, MSFrameworkSession>(); builder.AddLocalEventBus(); Singleton <IIdGenerator> .Instance = new IdGenerator(); return(services.BuildAspectInjectorProvider()); }
public static MSFrameworkBuilder UseNumberEncoding(this MSFrameworkBuilder builder, string path = "number_encoding.txt") { string codes; if (!File.Exists(path)) { codes = NumberEncoding.GetRandomCodes(); File.WriteAllText(path, codes); } else { codes = File.ReadAllLines(path).FirstOrDefault(); } if (string.IsNullOrWhiteSpace(codes) || codes.Length < 34) { throw new ArgumentException("Codes show large than 34 char"); } NumberEncoding.Load(codes); return(builder); }
public static MSFrameworkBuilder AddInMemoryEventStore(this MSFrameworkBuilder builder) { builder.Services.AddSingleton <IEventStore, InMemoryEventStore>(); return(builder); }
public static MSFrameworkBuilder UseEventDispatcher(this MSFrameworkBuilder builder, params Assembly[] assemblies) { builder.Services.AddEventDispatcher(assemblies); return(builder); }
public static MSFrameworkBuilder UseRequestProcessor(this MSFrameworkBuilder builder, params Assembly[] assemblies) { builder.Services.AddRequestProcessor(assemblies); return(builder); }