/// <summary> /// the basic ctor /// </summary> /// <param name="factory">the ambient context factory</param> protected BaseService( IAmbientDbContextFactory factory ) { AmbientDbContextStorageProvider.SetStorage(new AsyncLocalContextStorage()); ContextFactory = factory; ContextFactory.Create(); }
/// <summary> /// this method configures the services container for dependency injection /// </summary> /// <param name="services">the services container from the system's injection process</param> // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddCors(options => { var clientUrl = Configuration.GetSection("ClientUrl").Value; options.AddPolicy(name: _myCorsPolicyName, builder => { builder.WithOrigins(clientUrl) .AllowAnyHeader() .AllowAnyMethod(); }); }); services.AddControllers(); services.AddSingleton <IConfiguration>(Configuration); AmbientDbContextStorageProvider.SetStorage(new AsyncLocalContextStorage()); services.AddTransient <IDbConnectionFactory, DbConnectionFactory>(); services.AddTransient <IAmbientDbContextFactory, AmbientDbContextFactory>(); services.AddTransient <IAmbientDbContextLocator, AmbientDbContextLocator>(); services.AddTransient <IActivityService, ActivityService>(); services.AddTransient <ICommentService, CommentService>(); services.AddTransient <IPersonService, PersonService>(); services.AddTransient <IActivityRepository, ActivityRepository>(); services.AddTransient <ICommentRepository, CommentRepository>(); services.AddTransient <IPersonRepository, PersonRepository>(); services.AddTransient <IActivityValidators, ActivityValidators>(); services.AddTransient <ICommentValidators, CommentValidators>(); services.AddTransient <IPersonValidators, PersonValidators>(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "ActivitySignUpApi", Version = "v1" }); //c.OperationFilter<ExamplesOperationFilter>(); // Set the comments path for the Swagger JSON and UI. var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); c.IncludeXmlComments(xmlPath); }); services.Configure <FormOptions>(o => { o.ValueLengthLimit = int.MaxValue; o.MultipartBodyLengthLimit = int.MaxValue; o.MemoryBufferThreshold = int.MaxValue; }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { AmbientDbContextStorageProvider.SetStorage(new AsyncLocalContextStorage()); services.AddSingleton <IDbConnectionFactory>(provider => new SqlServerConnectionFactory("your connection string")); services.AddSingleton <IAmbientDbContextFactory, AmbientDbContextFactory>(); services.AddTransient <IAmbientDbContextLocator, AmbientDbContextLocator>(); services.AddTransient <AnUpdateQuery>(); services.AddTransient <AnInsertQuery>(); services.AddMvc(); }
public static void AssemblyInit(TestContext testContext) { Configuration = GetIConfigurationRoot(testContext.TestRunDirectory); AmbientDbContextStorageProvider.SetStorage(new AsyncLocalContextStorage()); ContextFactory = new AmbientDbContextFactory(new DbConnectionFactory(Configuration)); ContextFactory.Create(); ContextLocator = new AmbientDbContextLocator(); DbContext = ContextLocator.Get(); }
/// <summary> /// Configures application dependencies. /// </summary> /// <param name="builder">Autofac builder.</param> /// <param name="configuration">Application configuration.</param> public static ContainerBuilder Configure(ContainerBuilder builder, IConfiguration configuration) { var currentAssembly = Assembly.GetExecutingAssembly(); var assemblies = currentAssembly .GetReferencedAssemblies() .Select(an => Assembly.Load(an)) .ToArray(); builder.RegisterAssemblyTypes(currentAssembly).PublicOnly(); AmbientDbContextStorageProvider.SetStorage(new LogicalCallContextStorage()); var connectionString = SQLiteConnectionStringParser.Parse(configuration.GetConnectionString("DefaultConnection")); builder.RegisterInstance(new DefaultConnectionFactory(connectionString)).As <IDbConnectionFactory>().SingleInstance(); builder.RegisterType <AmbientDbContextFactory>().As <IAmbientDbContextFactory>().SingleInstance(); builder.RegisterType <AmbientDbContextLocator>().As <IAmbientDbContextLocator>(); builder.RegisterType <DapperRepository>().As <IRepository>(); builder.RegisterInstance(configuration.GetConfiguration <WindowSettings>()); builder.RegisterType <ApplicationState>().As <IApplicationState>().SingleInstance(); builder.RegisterType <InteractionService>().As <IInteractionService>().SingleInstance(); builder.RegisterType <BackgroundTask>().As <IBackgroundTask>().SingleInstance(); builder.RegisterType <AutofacHandlerFactory>().As <IHandlerFactory>().SingleInstance(); builder.RegisterType <DefaultMessageBus>().As <IMessageBus>().SingleInstance(); builder.RegisterType <DefaultNotificationStrategy>().As <INotificationStrategy>().AsSelf().InstancePerLifetimeScope(); builder.RegisterType <FireAndForgetNotificationStrategy>().As <INotificationStrategy>().AsSelf().InstancePerLifetimeScope(); builder.RegisterType <AutofacNotificationStrategyFactory>().As <INotificationStrategyFactory>().SingleInstance(); foreach (var assembly in assemblies) { builder.RegisterAssemblyTypes(assembly).AsClosedTypesOf(typeof(IRequestHandler <,>)); builder.RegisterAssemblyTypes(assembly) .Where(t => !t.Name.EndsWith("Decorator")) .AsClosedTypesOf(typeof(INotificationHandler <>)) .InstancePerLifetimeScope(); } builder.RegisterAssemblyModules(assemblies); return(builder); }
private static void Main(string[] args) { AmbientDbContextStorageProvider.SetStorage(new AsyncLocalContextStorage()); Task.Run(() => MainAsync(args)).Wait(); }