DI를 OWIN CreatePerOwinContext
확장자로 사용하려고합니다. 나는 OAuthAuthorizationServerProvider
도 사용하고 있습니다. OAuthAuthorizationServerProvider 내부에서 다음을 사용하여 내 사용자 관리자의 인스턴스를 가져 오려고합니다. OAuthGrantResourceOwnerCredentialsContext.OwinContext.GetUserManager.CreatePerOwinContext와 함께 Dependency Injection을 사용하려고 할 때 ObjectDisposedException
시작 UP 파일 :
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
{
//Inspecting the _userManager I see the ObjectDisposedException
_userManager = context.OwinContext.GetUserManager<AppUserManager>();
var user = await _userManager.FindByNameAsync(context.UserName);
}
: 나는
AppUserManager
의 인스턴스를 얻으려고 내
OAuthAuthorizationServerProvider
구현의
GrantResourceOwnerCredentials
내부
private static readonly Lazy<IUnityContainer> Container = new
public static IUnityContainer GetConfiguredContainer()
{
return Container.Value;
}
Lazy<IUnityContainer>(() => {
var container = new UnityContainer();
//Registers the Types
Register(container);
return container;
});
:
public void Configuration(IAppBuilder app)
{
DataProtectionProvider = app.GetDataProtectionProvider();
var config = new HttpConfiguration {DependencyResolver = new UnityDependencyResolver(UnityRegistrations.GetConfiguredContainer())};
WebApiConfig.Register(config);
//Allow Cross Domain Calls
app.UseCors(CorsOptions.AllowAll);
//I verified that my AppUserManager is getting constructed properly
//var manager = UnityRegistrations.GetConfiguredContainer().Resolve<AppUserManager>();
app.CreatePerOwinContext(() => UnityRegistrations.GetConfiguredContainer().Resolve<AppUserManager>());
OAuthOptions = new OAuthAuthorizationServerOptions
{
// Point at which the Bearer token middleware will be mounted
TokenEndpointPath = new PathString("/token"),
// An implementation of the OAuthAuthorizationServerProvider which the middleware
// will use for determining whether a user should be authenticated or not
Provider = new OAuthProvider("self"),
// How long a bearer token should be valid for
AccessTokenExpireTimeSpan = TimeSpan.FromHours(24),
// Allows authentication over HTTP instead of forcing HTTPS
AllowInsecureHttp = true
};
app.UseOAuthBearerTokens(OAuthOptions);
app.UseWebApi(config);
}
이것은 GetConfiguredContainer
방법
내가 무엇입니까? 웹 API와 Owin으로도 가능한 일을하려고합니까?