private void RegisterSqlStore(ILogger logger) { var verifier = new ProviderVerifier(); if (_configuration.SqlStore == null || string.IsNullOrEmpty(_configuration.SqlStore?.ConnectionString) || !verifier.IsSqlServiceRunning(_configuration.SqlStore?.ConnectionString, logger)) { _autofacContainerBuilder.RegisterType <NullSqlStore>() .As <ISqlStore>() .SingleInstance(); return; } _autofacContainerBuilder.Register(ctx => { var transactionContext = AmbientTransactionContext.Current; var unitOfWork = (UnitOfWork)transactionContext?.Items["UnitOfWork"]; if (unitOfWork != null) { return(unitOfWork.SqlStore); } return(new SqlStore(GetEntitiesInheritingFrom(typeof(IEntity <long>)), _configuration.SqlStore, false)); }) .As <ISqlStore>() .InstancePerLifetimeScope(); }