public EnrollmentRequest() { using (var serviceScope = ServiceActivator.GetScope()) { _validators = serviceScope.ServiceProvider.GetServices <IValidator <EnrollmentRequest> >(); }; }
public void RemoveCachedItem(RoutedItem routedItem) { using var scope = ServiceActivator.GetScope(); var cacheService = scope.ServiceProvider.GetRequiredService <IConnectionCacheResponseService>(); cacheService.RemoveCachedItem(Connection, routedItem, cache); }
public async Task SendToRules(int taskID, bool responsive = true) { using var scope = ServiceActivator.GetScope(); var adapter = scope.ServiceProvider.GetRequiredService <IConnectionToRulesManagerAdapter>(); var args = new ConnectionToRulesManagerAdapterArgs(Connection, toRules, cache, this); await adapter.SendToRules(taskID, args, responsive); }
/// <summary> /// result cache where we consolidate multiple routed items based on the same id.The result is added onto the id: key /// which usually arrives in chronological order(Pending, Pending, Success) though not required /// </summary> /// <param name="routedItem"></param> /// <returns></returns> public RoutedItem CacheResponse(RoutedItem routedItem) { using (var scope = ServiceActivator.GetScope()) { var cacheService = scope.ServiceProvider.GetRequiredService <IConnectionCacheResponseService>(); return(cacheService.CacheResponse(Connection, routedItem, cache)); } }
///<inheritdoc/> public override void Validate() { IStringLocalizer <UserCredentialToken> localizer = ServiceActivator.GetScope().ServiceProvider.GetService <IStringLocalizer <UserCredentialToken> >(); AddNotifications(new RequiredValidationContract <Guid?>(UserId, nameof(UserId), localizer["USER_REQUIRED"]).Contract.Notifications); if (ExpiresOn <= CreatedAt) { AddNotification("Dates", localizer["EXPIRED_DATE_IN_PAST"]); } }
/// <summary> /// Validate entity /// </summary> public override void Validate() { IStringLocalizer <User> localizer = ServiceActivator.GetScope().ServiceProvider.GetService <IStringLocalizer <User> >(); if (CreatedAuthor != null) { AddNotifications(CreatedAuthor.Notifications); } if (ChangedAuthor != null) { AddNotifications(ChangedAuthor.Notifications); } AddNotifications(Name.Notifications); AddNotifications(Email.Notifications); AddNotifications(new RequiredValidationContract <string>(Email?.Address, $"Email.{nameof(Email.Address)}", localizer["EMAIL_REQUIRED"]).Contract.Notifications); AddNotifications(new RequiredValidationContract <UserType?>(Type, nameof(Type), localizer["USER_TYPE_REQUIRED"]).Contract.Notifications); AddNotifications(new PastDateValidationContract(BornDate, "Born date", localizer["BORN_DATE_REQUIRED"]).Contract.Notifications); if (Credential != null) { Credential.Validate(); AddNotifications(Credential.Notifications); } if ((Type ?? UserType.User) == UserType.User) { AddNotifications(new BrasilianCpfValidationContract(Document, nameof(Document), true).Contract.Notifications); if (!Scopes.Any()) { AddNotification(nameof(Scopes), localizer["USER_IN_ONE_SCOPE"]); } else { Scopes .ToList() .ForEach(scope => { scope.Validate(); AddNotifications(scope.Notifications); }); } if (Roles != null && !Roles.Any()) { Roles .ToList() .ForEach(role => { role.Validate(); AddNotifications(role.Notifications); }); } } }
private static IFlurlRequest WithAuthentication(this IFlurlRequest req) { using (var serviceScope = ServiceActivator.GetScope()) { IAuthService authService = serviceScope.ServiceProvider.GetService <IAuthService>(); IOptions <RedoxApiConfig> config = (IOptions <RedoxApiConfig>)serviceScope.ServiceProvider.GetService(typeof(IOptions <RedoxApiConfig>)); // Authenticate user access authService.AuthenticateAsync(config.Value.Key, config.Value.Secret).Wait(); // Add authorization header req.WithOAuthBearerToken(authService.AccessToken); } return(req); }
private static void LoadSatelliteAssemblies() { var assemblies = AppDomain.CurrentDomain.GetAssemblies(); var assemblyPath = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location); if (assemblyPath == null) { return; } AssemblyLoadContext.Default.Resolving += ResolveDependencies; using (var serviceScope = ServiceActivator.GetScope()) { var localizationManager = serviceScope.ServiceProvider.GetService <ILocalizationManager>(); foreach (var culture in localizationManager.GetSupportedCultures()) { if (culture == Constants.DefaultCulture) { continue; } var assembliesFolder = new DirectoryInfo(Path.Combine(assemblyPath, culture)); foreach (var assemblyFile in assembliesFolder.EnumerateFiles(Constants.StalliteAssemblyExtension)) { AssemblyName assemblyName; try { assemblyName = AssemblyName.GetAssemblyName(assemblyFile.FullName); } catch { Console.WriteLine($"Not Satellite Assembly : {assemblyFile.Name}"); continue; } try { Assembly assembly = AssemblyLoadContext.Default.LoadFromStream(new MemoryStream(File.ReadAllBytes(assemblyFile.FullName))); Console.WriteLine($"Loaded : {assemblyName}"); } catch (Exception e) { Console.WriteLine($"Failed : {assemblyName}\n{e}"); } } } } }
/// <summary> /// Validate entity /// </summary> public override void Validate() { IStringLocalizer <Role> localizer = ServiceActivator.GetScope().ServiceProvider.GetService <IStringLocalizer <Role> >(); if (CreatedAuthor != null) { AddNotifications(CreatedAuthor.Notifications); } if (ChangedAuthor != null) { AddNotifications(ChangedAuthor.Notifications); } AddNotifications(new RequiredValidationContract <Guid?>(Scope?.Id, nameof(Scope), localizer["SCOPE_REQUIRED"]).Contract.Notifications); AddNotifications(new SimpleStringValidationContract(Name, nameof(Name), true, 3, 50).Contract.Notifications); AddNotifications(new SimpleStringValidationContract(Description, nameof(Description), true, 3, 150).Contract.Notifications); }
public static ISundayServicesConfiguration LoadConfiguration(this ISundayServicesConfiguration services, IWebHostEnvironment hostingEnv, IConfiguration configuration) { var environment = configuration.GetValue <string>("Environment"); var configurationPath = string.IsNullOrEmpty(environment) ? $"\\config\\sunday.config" : $"\\config\\sunday.{environment.ToLower()}.config"; using (var serviceScope = ServiceActivator.GetScope()) { var configFileContent = File.ReadAllText(hostingEnv.WebRootPath + configurationPath); var serializer = new XmlSerializer(typeof(ConfigurationNode)); using (TextReader reader = new StringReader(configFileContent)) { ConfigurationNode configurationNode = (ConfigurationNode)serializer.Deserialize(reader); AddSetting(configurationNode); AddPipelines(configurationNode); } } return(services); }
protected override void OnParametersSet() { IsLocalizable = false; if (!String.IsNullOrEmpty(ResourceKey) && ModuleState?.ModuleType != null) { var moduleType = Type.GetType(ModuleState.ModuleType); if (moduleType != null) { using (var scope = ServiceActivator.GetScope()) { var localizerFactory = scope.ServiceProvider.GetService <IStringLocalizerFactory>(); _localizer = localizerFactory.Create(moduleType); IsLocalizable = true; } } } }
public static void ReleaseToken(Token token, string uri) { ILogger _logger = null; var clientName = ""; var serverName = ""; try { using var serviceScope = ServiceActivator.GetScope(); clientName = ProcessExtractor.ProcessName(); serverName = ServerExtractor.ServerName(new Uri(uri)); _logger = serviceScope?.ServiceProvider?.GetService <ILoggerFactory>()?.CreateLogger("TokenGenExt"); var igrantToken = serviceScope?.ServiceProvider?.GetServices <IGrantToken>()?.FirstOrDefault(x => x.ServerName.Equals(serverName, StringComparison.InvariantCultureIgnoreCase)); igrantToken?.Release(clientName, token?.Id); } catch (Exception e) { _logger?.LogError(e, $"--Exception while releasing token for Server: {serverName} & Client:{clientName}"); } }
private Task HandleExceptionAsync(HttpContext context, Exception exception) { using var serviceScope = ServiceActivator.GetScope(); //serviceScope.ServiceProvider.GetRequiredService<IErrorLogsRepo>().Post(new ErrorLog() //{ // ExceptionMessage = exception.Message, // StackTrace = exception.StackTrace, // Source = exception.Source, // CreatedDate = DateTime.UtcNow //}, true); context.Response.ContentType = "application/json"; context.Response.StatusCode = (int)HttpStatusCode.OK; return(context.Response.WriteAsync(JsonConvert.SerializeObject(new ResponseDTO <string>() { Status = (int)HttpStatusCode.InternalServerError, Message = "Something unexpected happened! please review data for more details.", Data = exception.StackTrace }))); }
protected override void OnParametersSet() { if (!String.IsNullOrEmpty(ResourceKey)) { if (ModuleState?.ModuleType != null) { var moduleType = Type.GetType(ModuleState.ModuleType); var localizerTypeName = $"Microsoft.Extensions.Localization.IStringLocalizer`1[[{moduleType.AssemblyQualifiedName}]], Microsoft.Extensions.Localization.Abstractions"; var localizerType = Type.GetType(localizerTypeName); // HACK: Use ServiceActivator instead of injecting IHttpContextAccessor, because HttpContext throws NRE in WebAssembly runtime using (var scope = ServiceActivator.GetScope()) { _localizer = (IStringLocalizer)scope.ServiceProvider.GetService(localizerType); } } IsLocalizable = true; } else { IsLocalizable = false; } }
public ValidationProblemDetailsResult() { using IServiceScope serviceScope = ServiceActivator.GetScope(); logger = serviceScope.ServiceProvider.GetService <ILogger <ValidationProblemDetailsResult> >(); }