我有一个具有 AAD 身份验证的 Web API(在代码中,因为它在 IaaS 而不是 PaaS 中运行)它运行良好,但是如果我将 Autofac 配置添加到 Startup.cs,身份验证中断,(如果我在 Auth 初始化 Autofac 中断之后放置 Autofac ) 这让我认为配置正在相互覆盖。
我试图找到有关如何将它们一起使用的任何文档,但我找不到任何信息。一个使用 HttpConfiguration,另一个使用 IAppBuilder,我不知道如何将它们组合在一起以使它们一起工作。
这是我的身份验证代码:
public void ConfigureAuth(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.Map("/api", inner =>
{
inner.UseWindowsAzureActiveDirectoryBearerAuthentication(new WindowsAzureActiveDirectoryBearerAuthenticationOptions()
{
Tenant = tenant,
TokenValidationParameters = new Tokens.TokenValidationParameters
{
ValidAudience = Audience
}
});
});
}
这是Autofac代码
public static void Register(HttpConfiguration configuration)
{
var builder = new ContainerBuilder();
Bootstrapper.Configure(builder);
var container = builder.Build();
configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container);
}
一起使用这两个工具的最佳实践是什么?