public static DropletBuilder UseAutoMapper(this DropletBuilder @this) { var registrar = new AutoMapperRegistrar(@this.ServiceCollection, @this.RegisterAssemblies.ToArray()); registrar.CreateMap(); return(@this); }
public static DropletBuilder UseAutoDI(this DropletBuilder @this, Action <AutoDIBuilder> action = null) { var dotnetRegister = new DotnetRegister(@this.ServiceCollection); var registrar = new ComponentRegistrar(dotnetRegister); registrar.RegisterAssembly(@this.RegisterAssemblies.ToArray()); var builder = new AutoDIBuilder(registrar, @this.RegisterAssemblies); action?.Invoke(builder); return(@this); }
public static DropletBuilder UseEntityFrameworkCore <TContext>(this DropletBuilder builder, Action <DbContextOptionsBuilder> optionsAction = null) where TContext : DbContext { builder.AddMediator(); builder.ServiceCollection.AddDbContext <TContext>(optionsAction); builder.ServiceCollection.AddScoped(typeof(IUnitOfWork), typeof(EntityFrameworkCoreUnitOfWork <TContext>)); builder.ServiceCollection.RegisterGenericRepositoriesAndMatchDbContexes(typeof(TContext)); builder.ServiceCollection.Scan(scan => scan.FromAssemblies(builder.RegisterAssemblies) .AddClasses(classes => classes.AssignableTo(typeof(IRepository <>))) .AsImplementedInterfaces().WithTransientLifetime() ); return(builder); }
public void TestAddEntityFrameworkCore() { var services = new ServiceCollection(); var builder = new DropletBuilder(services, new List <System.Reflection.Assembly>() { typeof(EntityFrameworkCoreBuilderExtensions_Test).Assembly }); builder.AddEntityFrameworkCore <TestDbContext>(null); var serviceProvider = services.BuildServiceProvider(); var testRepository = serviceProvider.GetService <IRepository <Test> >(); Assert.IsNotNull(testRepository); Assert.AreEqual(testRepository.GetType(), typeof(TestRepository)); Assert.IsNotNull(serviceProvider.GetService <IRepository <TestWithId, int> >()); Assert.IsNotNull(serviceProvider.GetService <INullRepository>()); }
/// <summary> /// 使用多个连接的RawRabbit /// </summary> /// <param name="builder"></param> /// <param name="multipleRawRabbitConfigurationBuilderAction"></param> /// <param name="rawRabbitBuilderAction"></param> /// <returns></returns> public static DropletBuilder UseMultipleConnectionRawRabbit(this DropletBuilder builder, Action <MultipleRawRabbitConfigurationBuilder> multipleRawRabbitConfigurationBuilderAction, Action <RawRabbitBuilder> rawRabbitBuilderAction = null) { var multipleRawRabbitConfigurationBuilder = new MultipleRawRabbitConfigurationBuilder(); multipleRawRabbitConfigurationBuilderAction.Invoke(multipleRawRabbitConfigurationBuilder); var rawRabbitBuilder = new RawRabbitBuilder(builder); rawRabbitBuilderAction?.Invoke(rawRabbitBuilder); Dictionary <string, RawRabbitOptions> rawRabbitOptionsDic = new Dictionary <string, RawRabbitOptions>(); foreach (var item in multipleRawRabbitConfigurationBuilder.RawRabbitConfigurationDic) { if (item.Value.IsDefault) { builder.UseRawRabbit(item.Value.Configuration, rawRabbitBuilderAction); } rawRabbitOptionsDic.Add(item.Key, new RawRabbitOptions() { ClientConfiguration = item.Value.Configuration, Plugins = p => { if (rawRabbitBuilder.ClientBuilderAction == null) { p.UseExtensionRetryLater(); } else { rawRabbitBuilder.ClientBuilderAction(p.UseExtensionRetryLater()); } }, }); } builder.ServiceCollection.AddSingleton <IBusClientFactory>(new BusClientFactory(rawRabbitOptionsDic)); return(builder); }
private static void AddMediator(this DropletBuilder builder) { builder.ServiceCollection.AddScoped <ServiceFactory>(p => p.GetService); builder.ServiceCollection.AddScoped <IMediator, Mediator>(); builder.ServiceCollection.AddMediatR(builder.RegisterAssemblies.ToArray()); }