我有一个使用Ninject 2.0的ASP.NET 3.5 WebForms应用程序.但是,尝试使用Ninject.Web扩展来向System.Web.UI.Page提供注入,即使我切换到使用服务定位器来提供引用,我也会得到对我注入的依赖项的空引用(使用Ninject ),没有问题.
我的配置(为简单而愚蠢):
public partial class Default : PageBase // which is Ninject.Web.PageBase
{
[Inject]
public IClubRepository Repository { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
var something = Repository.GetById(1); // results in null reference exception.
}
}
Run Code Online (Sandbox Code Playgroud)
... //global.asax.cs
public class Global : Ninject.Web.NinjectHttpApplication
{
/// <summary>
/// Creates a Ninject kernel that will be used to inject objects.
/// </summary>
/// <returns>
/// The created kernel.
/// </returns>
protected override IKernel CreateKernel() …Run Code Online (Sandbox Code Playgroud) 根据http://ayende.com/blog/4599/hunt-the-bug,我遇到了其中一种情况,即"在这种情况下无法提供响应".
非常简化,以下内容在Windows Server 2008/IIS7/ASP.NET 4.0的某些情况下引发异常
public class Global : HttpApplication
{
public void Application_Start(object sender, EventArgs e)
{
HttpUtility.UrlEncode("Error inside!");
}
}
Run Code Online (Sandbox Code Playgroud)
我见过的解决方案涉及以下其中一项:
也许这不是我最好的谷歌搜索日,但如何实现HttpEncoder.Default?
建议?
场景:
<Row />- > <Cell />)以重复使用代码.<ShippingTable /><Grid /><Row />- > <Cell />).this.props.data.map循环,因为只有一个对象).问题:
this.props.data被传递给儿童,状态通过各种事件更新,一切都很好.<Row />.尽管this.props.data包含有效值并且已正确分配给子<Cell />组件,但在<Cell />getInitialState中,它是莫名其妙地未定义(或设置为<ShippingTable />s中设置的任何初始值getInitialState).尽管如此,除了在.map循环中调用之外,它与我的数据数组的相同渲染中的代码和数据完全相同.this.props.data在<Cell />'s render中确实存在且准确,但由于getInitialState中的setState失败,this.state.data未定义(或设置为<ShippingTable />s中设置的任何值getInitialState).<ShippingTable />),一切都会像我期望的那样起作用.这是因为如果getInitialState在<Cell />只有我一个百分比对象被的setState的成功AJAX人口之前调用,或者它没有被调用时,再次状态与从服务器更新后的数据被填充后改变.
这是实际代码的精简版(但仍然很长):
更新 - 解决
永远不要忘记,使用React,总是发送道具,发送事件,并始终保持状态尽可能远.删除<Cell />并执行<Row />状态跟踪职责,将它们移回到ShippingTable(而不是引用父级传递的props),其中实际跟踪状态(并且应始终跟踪).根据下面的@rallrall,我偏离了轨道并且莫名其妙地反对该框架.一切都非常清楚(尽管为什么不正确的方法适用于阵列而不是对象确实混淆了水域 …
我有以下几个绑定多个锚元素与类'团队'是x可编辑的select2输入.每个a.team都有一个不同的数据源(传递给Web服务的ID不同,以便返回适用的团队列表),但不幸的是,一旦绑定了第一个a.team,就会使用该数据源URL对于页面上的所有后续a.team输入(因此,错误的团队列表将绑定到每个后续的x-editable select2输入).
是否可以"重置"select2的data属性,以便它尊重每个a.team元素的每个数据源?或任何其他解决方案?
$('a.team').editable({
ajaxOptions: {
dataType: 'json',
type: 'POST'
},
emptytext: 'TBD',
placement: 'bottom',
success: function (response, newValue) {
return editableResponse(response, newValue);
},
select2: {
allowClear: true,
placeholder: 'Select a team',
width: '200px',
id: function (item) {
return item.id;
},
ajax: {
dataType: 'json',
results: function (data, page) {
return { results: data };
}
},
}
});
Run Code Online (Sandbox Code Playgroud)
多个a.team锚定在页面上,如下所示:
<a href="#" class="ur-team label label-inverse" data-type="select2" data-pk="@match.Id" data-source="@Url.Action("GetTeams", "Teams", new { scheduleId = match.ScheduleId })" data-value="@match.AwayTeamId" data-text="@match.AwayTeam" data-name="away" data-title="Update away …Run Code Online (Sandbox Code Playgroud) 如何处理子React输入控件中的小数,以便您可以成功输入例如"0.01"(没有奇数到最终用户的箭头导航等)?
场景:
例如:
handleChange: function(event) {
var value = event.target.value;
this.props.onChange(toDecimalOrWhateverFunction(value));
},
...
Run Code Online (Sandbox Code Playgroud)
问题:
适用于整数,但是一旦你开始输入小数,事情就会以"."的方式进行.和"0"条目,因为十进制转换删除任何小数点和零之后,您可以添加任何后续数字(记住,onChange作用于每个击键),输入的值设置为该数字的字符串表示(没有"."或"0")因为值= {this.props.whatever}
因此,"123"或"1.14"没有问题,因为该字符串最终分别为123和1.14.但是不能做"0.01"或"1.01"因为在完成小数之前分别向0和1点火.
我在React JS中处理小数错误还是处理这种情况的最佳做法?
更新:重复的答案不一定是一个明显的重复,因为在我寻求解决我的困境时,我没有找到它.但是,它的解决方案适用于我的场景,也可以适用于实际数据与用户可能查看/输入的数据类型或格式不匹配的其他场景.根据@WiredPrairie,"你需要存储字符串输入和十进制表示.字符串将存储用户键入的确切文本,另一个表示十进制值".
情况如下:
具体来说,尝试访问已知存在的静态文件的异常(即删除应用程序文件,特别是带有路由信息的DLL等,并且它没有问题地提供).同样,这发生在所有静态文件中,包括/public/scripts/jquery.js:
路径错误:/favicon.ico原始URL:/favicon.ico消息:找不到路径'/favicon.ico'.来源:System.Web堆栈跟踪:位于System.Web.Http应用程序中的System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()的System.Web.HttpNotFoundHandler.ProcessRequest(HttpContext上下文)(IExecutionStep) step,Boolean&completedSynchronously)TargetSite:Void ProcessRequest(System.Web.HttpContext)NLogLogger.Fatal => NLogLogger.Fatal => LoggerImpl.Write
我很困惑.我已经验证了测试默认的ASP.NET MVC 3应用程序在此计算机上的VS Development Server和本地IIS Web服务器下运行正常.
我希望其他人遇到类似的问题.万一有帮助,这是我的路线:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("favicon.ico");
routes.MapRoute(
"Login", // Route name
"login", // URL with parameters
new { controller = "Session", action = "Create" } // Parameter defaults
);
routes.MapRoute(
"Logout", // Route name
"logout", // URL with parameters
new { controller = "Session", action = "Delete" } // …Run Code Online (Sandbox Code Playgroud) 更新:请参阅文章的结尾,了解规范现在如何工作,我的规格/请求中的规格而不是规格/控制器.仍然想知道如何获得一个有效的登录用户与我的控制器进行集成测试.
我第一次使用Devise和CanCan,并且很难进行最基本的集成测试,我正在验证登录的用户是......好......登录.我已经阅读了无数帖子和与设计和RSpec集成测试处理(即答案加速起来经由直接访问会话https://github.com/plataformatec/devise/wiki/How-To%3a-Test-with-Capybara,HTTP:// schneems .com/post/15948562424/speed-up-capybara-tests-with-devise,以及Capybara,RSpec和Devise:通过绕过慢速登录和直接设置会话,可以更快地进行集成测试吗?但我一直无法做到得到一个标准的帖子按预期工作,我很困惑:
对于具有不同解决方案的类似问题的大量用户,我显然不是唯一一个遇到此问题的人,因为会话的各个方面等在不同场景中不可用.
剥离测试:
subject { page }
describe 'should be able to log in' do
before do
visit '/users/sign_in'
user = FactoryGirl.create(:admin)
#user.add_role :admin
fill_in 'Username', with: user.username
fill_in 'Password', with: user.password
click_on 'Sign in'
end
it { should have_link 'Logout' }
end
...
Run Code Online (Sandbox Code Playgroud)
相关的log.test输出:
Started POST "/users/sign_in" for 127.0.0.1 at 2012-11-06 17:31:10 -0800
Processing by Devise::SessionsController#create as HTML
Parameters: {"utf8"=>"?", "user"=>{"username"=>"username1", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Sign in"}
[1m[36mUser …Run Code Online (Sandbox Code Playgroud) 给定一个选择控件,您希望在表单加载时选择适用的选项(通过在控制器中明显保湿您的模型),如何在RSpec/Capybara集成测试中确定是否实际选择了正确的选项?
例如,给定以下选择控件...
<select class="select optional" id="receiving_tally_po_id" name="receiving_tally[po_id]">
<option value="10020">PO-10020 - Schoen Inc</option>
<option value="10018" selected="selected">PO-10018 - Senger, Eichmann and Murphy</option>
</select>
Run Code Online (Sandbox Code Playgroud)
...你如何测试值10018上的selected ="selected"?
describe "auto-populate with PO information" do
let!(:po) { FactoryGirl.create(:po) }
before { visit new_receiving_tally_path(:po => po) }
# The following checks to see if the option is actually there, but not if it's selected.
it { should have_xpath "//select[@id = '#receiving_tally_po_id']/option[@value = '#" + po.id.to_s + "' ]" }
end
Run Code Online (Sandbox Code Playgroud)
更新....另一个刺,但它似乎忽略了块项目(它表示即使有错误的信息也很好 - 原因可能很明显):
it "should have the …Run Code Online (Sandbox Code Playgroud) 我在 ASP.NET MVC 应用程序中将 Castle Windsor 与 NHIbernate 一起用于 IoC。它运行良好,注册如下(有一个例外):
container.Register(Component.For<ISessionFactoryBuilder.().ImplementedBy<SessionFactoryBuilder>().LifestyleSingleton());
// Register the NHibernate session factory as a singleton using custom SessionFactoryBuilder.BuildSessionFactory method.
container.Register(Component.For<ISessionFactory>().UsingFactoryMethod(k => k.Resolve<ISessionFactoryBuilder>().BuildSessionFactory("ApplicationServices")).LifestyleSingleton());
container.Register(Component.For<IInterceptor>().ImplementedBy<ChangeAuditInfoInterceptor>().LifestylePerWebRequest());
container.Register(Component.For<ISession>().UsingFactoryMethod(k => k.Resolve<ISessionFactory>()
.OpenSession(container.Resolve<IInterceptor>())).LifestylePerWebRequest());
Run Code Online (Sandbox Code Playgroud)
一切都很好,除了我的 ChangeAuditInterceptor 依次注入了 IAccountSession 服务,而 IAccountSession 服务又注入了 NHibernate ISession...这会导致以下循环依赖异常:
尝试解析组件“后期绑定 NHibernate.ISession”时检测到依赖循环。导致循环的解析树如下: 组件“后期绑定 NHibernate.ISession”解析为组件“Blah.Core.Services.AccountSession”的依赖项解析为组件“Blah.Core.Infrastruct.Data.ChangeAuditInfoInterceptor”的依赖项解析为组件“Blah.Core.Infrastruct.Installers.SessionFactoryBuilder”的依赖项 解析为组件“后期绑定 NHibernate.ISessionFactory”的依赖项 解析为组件“后期绑定 NHibernate.ISession”的依赖项,该组件是正在解析的根组件。
在过去的几年里,我通常使用 NHibernateSessionManager 来运行,它负责处理 IInterceptor 中的插入,而不会导致这种循环依赖问题(与使用 Castle Windsor 的 usingFactoryMethod 功能的 SessionFactoryBuilder 的这种用法相反)。
关于如何解决这种循环依赖有什么建议吗?还没有开始通过其他方式侵入 AccountSession 的 ISession(即绕过问题并因此产生气味的属性注入)。我已将 AccountSession 服务的 ISession 注入切换为属性注入,并且工作正常,但我不喜欢隐式契约与构造函数显式契约。
public class AccountSession : IAccountSession
{
private readonly ISession _session;
public …Run Code Online (Sandbox Code Playgroud) 我在某处看到了类似的东西(特别是如果实体是零,那么不显示部分),但我似乎无法复制功能.有没有办法简写以下内容?
<% if @sales_orders.any? %>
<%= render @sales_orders %>
<% else %>
<%= render 'shared/no_records' %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
就像是:
<%= render @sales_orders || 'no records found' %>
Run Code Online (Sandbox Code Playgroud)
或者(伪,但你得到漂移):
<%= @sales_orders ? render(@sales_orders) : render('shared/no_records') %>
Run Code Online (Sandbox Code Playgroud) asp.net ×2
capybara ×2
javascript ×2
reactjs ×2
rspec ×2
cancan ×1
devise ×1
isession ×1
jquery ×1
nhibernate ×1
ninject ×1
urlencode ×1
webforms ×1
x-editable ×1