本文整理汇总了C#中Autofac.Integration.WebApi.AutofacWebApiDependencyResolver.GetService方法的典型用法代码示例。如果您正苦于以下问题:C# AutofacWebApiDependencyResolver.GetService方法的具体用法?C# AutofacWebApiDependencyResolver.GetService怎么用?C# AutofacWebApiDependencyResolver.GetService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Autofac.Integration.WebApi.AutofacWebApiDependencyResolver
的用法示例。
在下文中一共展示了AutofacWebApiDependencyResolver.GetService方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetServiceReturnsNullForUnregisteredService
public void GetServiceReturnsNullForUnregisteredService()
{
var container = new ContainerBuilder().Build();
var resolver = new AutofacWebApiDependencyResolver(container);
var service = resolver.GetService(typeof(object));
Assert.That(service, Is.Null);
}
示例2: BuildAndSetResolver
/// <summary>
/// 构建服务并设置WebApi平台的Resolver
/// </summary>
/// <param name="services">服务映射信息集合</param>
/// <param name="assemblies">要检索的程序集集合</param>
/// <returns>服务提供者</returns>
protected override IServiceProvider BuildAndSetResolver(IServiceCollection services, Assembly[] assemblies)
{
ContainerBuilder builder = new ContainerBuilder();
builder.RegisterApiControllers(assemblies).AsSelf().PropertiesAutowired();
builder.RegisterWebApiFilterProvider(GlobalConfiguration.Configuration);
builder.RegisterWebApiModelBinderProvider();
builder.Populate(services);
IContainer container = builder.Build();
IDependencyResolver resolver = new AutofacWebApiDependencyResolver(container);
GlobalConfiguration.Configuration.DependencyResolver = resolver;
return (IServiceProvider)resolver.GetService(typeof(IServiceProvider));
}