本文整理汇总了C#中IServiceCollection.Where方法的典型用法代码示例。如果您正苦于以下问题:C# IServiceCollection.Where方法的具体用法?C# IServiceCollection.Where怎么用?C# IServiceCollection.Where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IServiceCollection
的用法示例。
在下文中一共展示了IServiceCollection.Where方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConfigureServices
public IServiceProvider ConfigureServices(IServiceCollection services)
{
_hostingEnv = services.Where(m => m.ServiceType == typeof(IHostingEnvironment) && m.ImplementationInstance != null).Select(m => m.ImplementationInstance).Last() as IHostingEnvironment;
_startup = new Startup(_hostingEnv);
ServiceProvider = services.BuildServiceProvider();
return ServiceProvider;
}
示例2: ServiceManifest
public ServiceManifest(IServiceCollection fallback)
{
var manifestTypes = fallback.Where(t => t.ServiceType.GetTypeInfo().GenericTypeParameters.Length == 0
&& t.ServiceType != typeof(IRuntimeServices)
&& t.ServiceType != typeof(IServiceProvider))
.Select(t => t.ServiceType).Distinct();
Services = manifestTypes;
}
示例3: MergeServiceDescriptions
private static void MergeServiceDescriptions(IServiceCollection serviceCollection, IEnumerable<ServiceDescriptor> serviceDescriptors)
{
var excludedServiceDescriptors = serviceCollection.Where(service => serviceDescriptors.Contains(service) == false);
foreach (var descriptor in excludedServiceDescriptors)
{
serviceCollection.Remove(descriptor);
}
foreach (var descriptor in serviceDescriptors)
{
serviceCollection.Add(descriptor);
}
}
示例4: ConfigureServices
// This method gets called by the runtime.
public IServiceProvider ConfigureServices(IServiceCollection services)
{
//var logger = loggerFactory.CreateLogger(typeof(Program).FullName);
//logger.LogInformation("Handled in {ExecutionTime} ms", executionTime);
Bifrost.Configuration.Configure.DiscoverAndConfigure(
assembliesConfigurationBuilderCallback: builder => builder.IncludeAll().ExceptAssembliesStartingWith("Microsoft"),
additionalAssemblyProviders: new[] { new LibraryAssemblyProvider() }
);
services.AddSignalR();
ContainerCreator.Kernel.Populate(services.Where(s => !s.HasBinding()));
return ContainerCreator.Kernel.Get<IServiceProvider>();
}
示例5: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddCustomPageCore();
services.AddTransient<IWidgetProvider, JsonWidgetProvider>();
var builder = new ContainerBuilder();
builder.Populate(services);
foreach (var descriptor in services.Where(i => i.ImplementationInstance is IModule))
{
builder.RegisterModule(descriptor.ImplementationInstance as IModule);
}
var container = builder.Build();
_serviceProvider = container.Resolve<IServiceProvider>();
}
示例6: AssertContainsSingle
private void AssertContainsSingle(
IServiceCollection services,
Type serviceType,
Type implementationType)
{
var matches = services
.Where(sd =>
sd.ServiceType == serviceType &&
sd.ImplementationType == implementationType)
.ToArray();
if (matches.Length == 0)
{
Assert.True(
false,
$"Could not find an instance of {implementationType} registered as {serviceType}");
}
else if (matches.Length > 1)
{
Assert.True(
false,
$"Found multiple instances of {implementationType} registered as {serviceType}");
}
}
示例7: AssertServiceCountEquals
private void AssertServiceCountEquals(
IServiceCollection services,
Type serviceType,
int expectedServiceRegistrationCount)
{
var serviceDescriptors = services.Where(serviceDescriptor => serviceDescriptor.ServiceType == serviceType);
var actual = serviceDescriptors.Count();
Assert.True(
(expectedServiceRegistrationCount == actual),
$"Expected service type '{serviceType}' to be registered {expectedServiceRegistrationCount}" +
$" time(s) but was actually registered {actual} time(s).");
}
示例8: PrepareRouteServices
private static void PrepareRouteServices(IServiceCollection serviceCollection)
{
var modelBindingActionInvokerFactoryType = typeof(IModelBindingActionInvokerFactory);
if (serviceCollection.All(s => s.ServiceType != modelBindingActionInvokerFactoryType))
{
serviceCollection.TryAddEnumerable(
ServiceDescriptor.Transient<IActionInvokerProvider, ModelBindingActionInvokerProvider>());
serviceCollection.TryAddSingleton(modelBindingActionInvokerFactoryType, typeof(ModelBindingActionInvokerFactory));
}
routeServiceProvider = serviceCollection.BuildServiceProvider();
serviceCollection.RemoveSingleton(modelBindingActionInvokerFactoryType);
var actionInvokerProviders = serviceCollection.Where(s => s.ServiceType == typeof(IActionInvokerProvider)).ToList();
if (actionInvokerProviders.Count > 1)
{
serviceCollection.Remove(actionInvokerProviders.LastOrDefault());
}
}