- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用 caSTLe.windsor 和 owin 在 webapi2 中获得了一些 DI。这是相关代码:
[assembly: OwinStartup(typeof(Bla.Startup))]
namespace Bla
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
//...
var container = new WindsorContainer().Install(new ControllerInstaller());
var httpDependencyResolver = new WindsorHttpDependencyResolver(container);
config.DependencyResolver = httpDependencyResolver;
//...
}
}
public class ControllerInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(AllTypes.FromThisAssembly()
.Pick().If(t => t.Name.EndsWith("Controller"))
.Configure(configurer => configurer.Named(configurer.Implementation.Name))
.LifestylePerWebRequest());
//...
}
}
internal class WindsorDependencyScope : IDependencyScope
{
private readonly IWindsorContainer _container;
private readonly IDisposable _scope;
public WindsorDependencyScope(IWindsorContainer container)
{
if (container == null)
{
throw new ArgumentNullException("container");
}
_container = container;
_scope = container.BeginScope();
}
public object GetService(Type t)
{
return _container.Kernel.HasComponent(t)
? _container.Resolve(t) : null;
}
public IEnumerable<object> GetServices(Type t)
{
return _container.ResolveAll(t)
.Cast<object>().ToArray();
}
public void Dispose()
{
_scope.Dispose();
}
}
internal sealed class WindsorHttpDependencyResolver : IDependencyResolver
{
private readonly IWindsorContainer _container;
public WindsorHttpDependencyResolver(IWindsorContainer container)
{
if (container == null)
{
throw new ArgumentNullException("container");
}
_container = container;
}
public object GetService(Type t)
{
return _container.Kernel.HasComponent(t)
? _container.Resolve(t) : null;
}
public IEnumerable<object> GetServices(Type t)
{
return _container.ResolveAll(t)
.Cast<object>().ToArray();
}
public IDependencyScope BeginScope()
{
return new WindsorDependencyScope(_container);
}
public void Dispose()
{
}
}
owin 的一大优点是它消除了对 system.web 的依赖。这允许从其他事物中执行相当有效的(在内存中?)集成测试。我面临的问题是这一行:
config.DependencyResolver = httpDependencyResolver;
引入对系统的依赖。所以当我尝试运行这样一个简单的测试时:
private TestServer _server;
[TestFixtureSetUp]
public void FixtureInit()
{
_server = TestServer.Create<Startup>();
}
[Test]
public voidSomeTest()
{
using (var server = TestServer.Create<Startup>())
{
HttpResponseMessage response = server.HttpClient.GetAsync("/api/bladibla/test").Result;
// ...
}
}
我得到:
{"Looks like you forgot to register the http module Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule\r\nTo fix this add\r\n<add name=\"PerRequestLifestyle\" type=\"Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.Windsor\" />\r\nto the <httpModules> section on your web.config.\...
我可以在测试项目的 app.config 中注册一些东西吗?非常欢迎任何反馈。
附言:
我尝试添加:
<system.web>
<httpModules>
<add name="PerRequestLifestyle" type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.Windsor" />
</httpModules>
</system.web>
<system.webServer>
<modules>
<add name="PerRequestLifestyle" type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.Windsor" />
</modules>
</system.webServer>
到 app.config 没有成功。
PPS:
好的,如果我改变:
container.Register(AllTypes.FromThisAssembly()
.Pick().If(t => t.Name.EndsWith("Controller"))
.Configure(configurer => configurer.Named(configurer.Implementation.Name))
.LifestylePerWebRequest());
到:
container.Register(AllTypes.FromThisAssembly()
.Pick().If(t => t.Name.EndsWith("Controller"))
.Configure(configurer => configurer.Named(configurer.Implementation.Name))
.LifestyleTransient());
它有效,这是有道理的。最大的问题是,我如何动态更改它,具体取决于它是在部署/适当的 Web 环境中还是在测试环境中。
最佳答案
{"Looks like you forgot to register the http module Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule\r\nTo fix this add\r\n\r\nto the section on your web.config....
但您尝试注册:
PerRequestLifestyle
看出区别了吗? PerWebRequestLifestyle 不是 PerRequestLifeStyle。
看看Mauricio Scheffer`s HybridLifeStyles这使得用于测试的容器的设置非常非常容易。
关于c# - 是什么导致错误 "Looks like you forgot to register the http module CaSTLe.MicroKernel.Lifestyle.PerWebRequestLifestyleModule"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25442578/
就目前情况而言,这个问题不太适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、民意调查或扩展讨论。如果您觉得这个问题可以改进并可能重新开放,visit
我有一个具有多种语言的 Magento 网站。我已经设置了语言包,网站上的所有内容似乎都能正确翻译。此外,交易电子邮件均以正确的语言发送,“忘记密码”电子邮件除外,该电子邮件始终以德语发送。这是我所做
我使用 SFHFKeychainUtils 有一段时间了。在我上次更新 AppStore 时,它突然“忘记”了我的用户密码。这意味着,当为相同的用户名和服务调用 getPasswordForUse
这个问题已经有答案了: 已关闭10 年前。 Possible Duplicate: Forgot Password: what is the best method of implementing a
这个问题在这里已经有了答案: Is this fire and forget approach correct? (2 个答案) Fire and forget without async void
我想尝试不同类型的 bean 作用域。所以我写了一个测试环境,它应该生成一个随机数,这样我就可以看到一个 bean 是否发生了变化。我的测试设置不起作用,我无法解释我发现了什么。 我正在使用 Spri
我有 md5 格式的密码数据库条目,但是当用户使用“忘记密码”时,我该如何给他/她所需的密码? 最佳答案 你不能从 MD5 散列中做到这一点;你也不应该能够。密码恢复应该是棘手的。 通常的过程是将密码
当你运行 perl -e "Bla->new" ,你会得到这个众所周知的错误: Can't locate object method "new" via package "Bla" (perhaps
我们在门户中使用 Keycloak 12 进行身份验证,并且有两种不同类型的用户: 内部用户(从我们的内部 LDAP 读取) 外部用户(存储在 Keycloak 中但未与 LDAP 同步) 我们现在想
在登录 demos ,每个示例都有说明“要关闭登录表单提交非空用户名和密码”的页脚文本。我想复制这个,但添加的不仅仅是文本。我可以打电话LoginI18n#setAdditionalInformati
这是我遇到的错误。 Warning: React.createElement: type is invalid -- expected a string (for built-in component
在从Devise切换到直接使用的过程中Warden . 我怎样才能实现 Devise 开箱即用的“忘记密码”功能? 是否有 gem 可以将此添加到 Warden 上? 附言。不使用 Devise 的原
我正在尝试将忘记密码字段与登录页面放在一起,但如果用户未注册(并且不在应用程序数据库中),则它会重定向到原始设计的忘记密码页面并出现错误 (http://localhost:3000/用户/密码)。如
我正在使用 ASW Cognito 对用户进行身份验证。 Cognito 有一个记录良好的流程来处理忘记密码的用户。 如何处理忘记用户名的用户?是否有内置流程让用户输入他们的电子邮件或电话号码,然后接
我正在使用具有 Azure AAD B2C 配置的 Web 应用程序来进行 IIS 中托管的身份验证。 我已创建注册策略、登录策略和密码重置策略。我也在 Azure Active Directory
我正在尝试实现一个包含“忘记密码?”的登录页面。按钮打开一个表单,然后允许用户提交电子邮件,同时也是用户名,如果 Cognito 中存在该条目,则应启动重置密码过程。 到目前为止,我遇到的问题之一是我
我想知道在网站上创建忘记密码功能的最佳方法是什么。我见过不少这样的东西,这里有一些或它们的组合: 密码问题/答案(1 个或多个) 发送包含新密码的电子邮件 在屏幕上输入新密码 通过电子邮件确认:必须点
我是 Azure AD B2C 的新手,因为 Azure B2C 提供了各种策略和用户流程,例如登录注册等。我们使用的是相同的。由于某种原因,我们考虑使用图形 API(更改密码)来实现忘记密码功能,在
如何从 Azure AD B2C 登录的登录页面中删除“忘记密码”链接。 谢谢。 最佳答案 在技术资料的元数据部分添加: none 选项: AfterLabel (Default) After
如何从 Azure AD B2C 登录的登录页面中删除“忘记密码”链接。 谢谢。 最佳答案 在技术资料的元数据部分添加: none 选项: AfterLabel (Default) After
我是一名优秀的程序员,十分优秀!