public static void AddNsb(this IServiceCollection services) { var licensePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "NSB_License.xml"); var config = new EndpointConfiguration("SignalRTest"); if (File.Exists(licensePath)) { config.LicensePath(licensePath); } config.UseTransport <LearningTransport>(); config.RegisterComponents( configComp => { configComp.ConfigureComponent(() => GetHubContext(services), DependencyLifecycle.InstancePerCall); }); var session = Endpoint.Start(config).Result; services.AddSingleton <IMessageSession>(session); }
public void AddValidators(IEnumerable <Result> results) { Guard.AgainstNull(results, nameof(results)); endpoint.RegisterComponents(components => { foreach (var result in results) { components.ConfigureComponent(result.ValidatorType, dependencyLifecycle); } }); }
public void AddValidatorsFromAssembly(Assembly assembly, bool throwForNonPublicValidators = true, bool throwForNoValidatorsFound = true) { var assemblyName = assembly.GetName().Name; if (throwForNonPublicValidators) { var openGenericType = typeof(IValidator <>); var nonPublicValidators = assembly .GetTypes() .Where(type => !type.IsPublic && !type.IsNestedPublic && !type.IsAbstract && !type.IsGenericTypeDefinition && type.GetInterfaces() .Any(i => i.GetTypeInfo().IsGenericType&& i.GetGenericTypeDefinition() == openGenericType) ) .ToList(); if (nonPublicValidators.Any()) { throw new Exception($"Found some non public validators were found in {assemblyName}:{Environment.NewLine}{string.Join(Environment.NewLine, nonPublicValidators.Select(x => x.FullName))}."); } } var results = AssemblyScanner.FindValidatorsInAssembly(assembly).ToList(); if (throwForNoValidatorsFound && !results.Any()) { throw new Exception($"No validators were found in {assemblyName}."); } endpoint.RegisterComponents(components => { foreach (var result in results) { components.ConfigureComponent(result.ValidatorType, dependencyLifecycle); } }); }