private static IItem FindSourceItemForElement(IProductElement element, Func <IEnumerable <IItem>, IItem> filter) { var references = ServiceProviderExtensions .GetService <IUriReferenceService>(element.Product.ProductState); var sourceFile = filter(SolutionArtifactLinkReference.GetResolvedReferences(element, references).OfType <IItem>()); return(sourceFile); }
protected void MergeLicensingResources(LicensingDialogBase dialog) { ResourceDictionary resourceDictionary = FileTable.GetResourceDictionary("Licensing/LicensingDialogResources.xaml"); dialog.Resources.MergedDictionaries.Add(resourceDictionary); ResourceDictionary licensingDialogResources = ServiceProviderExtensions.LicenseService((IServiceProvider)this.Services).LicensingDialogResources; if (licensingDialogResources == null) { return; } dialog.Resources.MergedDictionaries.Add(licensingDialogResources); }
public static string GetServiceTemplate(MethodInfo methodInfo, IServiceProvider serviceLocator) { var template = ServiceProviderExtensions.GetService <IRouteTemplateResolver>(serviceLocator)?.GetTemplate(methodInfo); if (!String.IsNullOrWhiteSpace(template)) { return(template); } var verbAttribute = methodInfo.GetCustomAttribute <VerbAttribute>(); var templateAttrib = methodInfo.GetCustomAttribute <IRouteAttribute>(); if (templateAttrib == null) { return(verbAttribute?.Route ?? template ?? ""); } template = templateAttrib.Template; return(template ?? ""); }
public void When_resolving_multiple_then_returns_all_registered_instances() { using (var container = new UnityContainer()) { container.RegisterInstance <IFoo>("instance1", new Foo { TestProperty = "value1" }); container.RegisterInstance <IFoo>("instance2", new Foo { TestProperty = "value2" }); var serviceCollection = new ServiceCollection(); Configuration.Register(serviceCollection, container); var resolver = container.Resolve <IServiceProvider>(); var actual = ServiceProviderExtensions.GetServices(resolver, typeof(IFoo)).Cast <IFoo>().ToList(); Assert.True(actual.Any(x => x.TestProperty == "value1")); Assert.True(actual.Any(x => x.TestProperty == "value2")); } }
public static void BuildParameterInfo(MethodInfo methodInfo, ActionWrapper action, IServiceProvider serviceLocator) { var parameterHandler = ServiceProviderExtensions.GetService <IServiceParameterResolver>(serviceLocator); if (parameterHandler != null) { var parameters = parameterHandler.ResolveParameters(methodInfo); if (parameters != null && parameters.Any()) { action.Parameters.AddRange(parameters); foreach (var pi in methodInfo.GetParameters()) { action.MessageExtesionLevel = pi.GetCustomAttribute <ExtensionLevelAttribute>() == null ? action.MessageExtesionLevel : pi.GetCustomAttribute <ExtensionLevelAttribute>().PropertInjectionLevel; } return; } } foreach (var parameterInfo in methodInfo.GetParameters()) { var @in = parameterInfo.GetCustomAttribute <InAttribute>(true); //if (@in == null) //{ // var fromBody = parameterInfo.GetCustomAttribute<FromBodyAttribute>(true); // if (fromBody != null) // @in = new InAttribute(InclutionTypes.Body); // if (@in == null) // { // var fromUri = parameterInfo.GetCustomAttribute<FromUriAttribute>(true); // if (fromUri != null) // @in = new InAttribute(InclutionTypes.Path); // } //} action.MessageExtesionLevel = parameterInfo.GetCustomAttribute <ExtensionLevelAttribute>() == null ? action.MessageExtesionLevel : parameterInfo.GetCustomAttribute <ExtensionLevelAttribute>().PropertInjectionLevel; action.Parameters.Add(new ParameterWrapper { Name = parameterInfo.Name, Type = parameterInfo.ParameterType, In = @in?.InclutionType ?? InclutionTypes.Body }); } }
public static List <HttpMethod> GetHttpMethods(List <VerbAttribute> actions, MethodInfo method, IServiceProvider serviceLocator) { var methodResolver = ServiceProviderExtensions.GetService <IWebMethodConverter>(serviceLocator); var methods = new List <HttpMethod>(); if (methodResolver != null) { methods.AddRange(methodResolver.GetHttpMethods(method)); } foreach (var actionHttpMethodProvider in actions) { methods.Add(new HttpMethod(actionHttpMethodProvider.Verb)); } if (methods.Count == 0) { methods.Add(HttpMethod.Get); } return(methods); }
public RegisterItemDialog(IServiceProvider services, ITrackedItemType type, IList <ITrackedItemType> allTypes, string defaultTitle, string defaultDescription, string[] fileAttachments) { this.services = services; this.configuration = ServiceProviderExtensions.GetService <IConfigurationService>(this.services)["SaveTFSWorkItem"]; this.defaultTitle = defaultTitle; this.defaultDescription = defaultDescription; this.fileAttachments = fileAttachments; this.allTypes = allTypes; this.InitializeComponent(); this.DataContext = (object)this; this.Title = StringTable.RegisterTFSItemDialogTitle; this.type = type; this.AcceptButton.Click += new RoutedEventHandler(this.Button_Click); this.CancelButton.Click += new RoutedEventHandler(this.Button_Click); this.ChooseButton.Click += new RoutedEventHandler(this.Button_Click); this.RegenerateForm(type); this.Height = (double)this.configuration.GetProperty("Height", (object)645.0); this.Width = (double)this.configuration.GetProperty("Width", (object)750.0); this.SizeChanged += new SizeChangedEventHandler(this.RegisterItemDialog_SizeChanged); }
private static void ConfigureServices() { var services = new ServiceCollection(); services.AddSingleton(typeof(Context)); services.AddTransient <IDepartmentRepository, DepartmentRepository>(); services.AddTransient <IEmployeeRepository, EmployeeRepository>(); services.AddTransient <IDepartmentService, DepartmentService>(); services.AddTransient <IEmployeeService, EmployeeService>(); services.AddTransient <ICourseRepository, CourseRepository>(); services.AddTransient <ICourseService, CourseService>(); services.AddTransient <ITeacherRepository, TeacherRepository>(); services.AddTransient <ITeacherService, TeacherService>(); ServiceProviderExtensions.AddControllersAsServices(services, typeof(RouteConfig).Assembly.GetExportedTypes() .Where(t => !t.IsAbstract && !t.IsGenericTypeDefinition) .Where(t => typeof(IController).IsAssignableFrom(t) || t.Name.EndsWith("Controller", StringComparison.OrdinalIgnoreCase))); DependencyResolver.SetResolver(new MyDependencyResolver(services.BuildServiceProvider())); }
public static string GetRouteTemplate(IRoutePrefix templatePrefix, IRoute template, MethodInfo methodInfo, IServiceProvider serviceLocator) { var interfaceType = methodInfo.DeclaringType; var templateResolver = ServiceProviderExtensions.GetService <IRouteTemplateResolver>(serviceLocator); var route = templateResolver?.GetTemplate(methodInfo); if (!String.IsNullOrWhiteSpace(route)) { return(route); } string prefix = ""; if (templatePrefix != null) { prefix = templatePrefix.Prefix; if (templatePrefix.IncludeTypeName) { prefix = prefix + "/" + (interfaceType.GetGenericArguments().Any() ? interfaceType.GetGenericArguments().FirstOrDefault()?.Name.ToLower() : interfaceType.GetInterfaces().FirstOrDefault()?.GetGenericArguments().First().Name.ToLower()); } } return((templatePrefix == null ? "" : (prefix + "/") + template.Template).Replace("//", "/")); }
public void When_Call_StartMessagingManager_Should_Start_Messaging_Manager() { ServiceProviderExtensions.StartMessagingManager(_serviceProviderMock.Object); _messagingManager.Verify(m => m.Start(), Times.Once); }
public void When_Call_StartMessagingManager_Should_Load_Processors() { ServiceProviderExtensions.StartMessagingManager(_serviceProviderMock.Object); _messagingManager.Verify(m => m.LoadProcessors(It.IsAny <IServiceProvider>()), Times.Once); }
public void When_Call_StartMessagingManager_Should_Get_IMessagingManager() { ServiceProviderExtensions.StartMessagingManager(_serviceProviderMock.Object); _serviceProviderMock.Verify(s => s.GetService(typeof(IMessagingManager)), Times.Once); }
public IFilterMetadata CreateInstance(IServiceProvider serviceProvider) { return(new ValidateHeaderAntiForgeryTokenAuthorizationFilter( ServiceProviderExtensions.GetRequiredService <IAntiforgery>(serviceProvider), ServiceProviderExtensions.GetRequiredService <IOptions <AntiforgeryOptions> >(serviceProvider))); }
public DataAccessGraphQLSchema(IServiceProvider services) : base(services) { this.Query = ServiceProviderExtensions.GetRequiredService <RootGraphQLQuery>(services); this.Mutation = ServiceProviderExtensions.GetRequiredService <RootGraphQLMutation>(services); }
public virtual async Task OnAuthorizationAsync(AuthorizationContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } // Allow Anonymous skips all authorization if (context.Filters.Any(item => item is IAllowAnonymousFilter)) { return; } var httpContext = context.HttpContext; // Check if Request is from Documentation Generator string documentationApiKey = httpContext.Request.Query[DocumentationApiKey]; if (!string.IsNullOrEmpty(documentationApiKey)) { if (documentationApiKey.Equals(DocumentationApiValue, StringComparison.InvariantCultureIgnoreCase)) { return; } context.Result = HttpResponseHelper.BadRequest($"Invalid value for {DocumentationApiKey}."); return; } StringValues header; var headerExists = httpContext.Request.Headers.TryGetValue(SessionHeaderName, out header); // Check if Session Header exists if (!headerExists) { context.Result = HttpResponseHelper.Unauthorized($"No {SessionHeaderName} Header found."); return; } Guid token; var isValidGuid = Guid.TryParse(header.FirstOrDefault(), out token); // Token value must be valid Guid if (!isValidGuid) { context.Result = HttpResponseHelper.Unauthorized($"Invalid {SessionHeaderName} Header."); return; } var localSession = SessionExtensions.GetObjectFromJson <Session>(httpContext.Session, "__session"); // If 'active' session already exists skip DB call if (localSession != null && localSession.Id.Equals(token) && localSession.Player != null) { return; } var db = ServiceProviderExtensions.GetRequiredService <SocialGamificationAssetContext>( httpContext.RequestServices); if (db == null) { context.Result = HttpResponseHelper.ErrorContentResult( "Unable to connect with requested Database service.", StatusCodes.Status503ServiceUnavailable); return; } var session = await db.Sessions.Where(s => s.Id.Equals(token)).Include(s => s.Player).FirstOrDefaultAsync(); // Find Session if (session == null) { context.Result = HttpResponseHelper.NotFound($"Session {token} is Invalid."); return; } // Set right Session SessionExtensions.SetObjectAsJson(httpContext.Session, "__session", session); }