我们有一个ASP.NET MVC应用程序,它具有许多不同的领域。在我们的服务层中,有2个区域使用相同的C#类,但是针对不同的基础数据。我希望这些服务根据路由数据中的值获得不同的依赖关系。
很难解释,我在解释我的班级/领域名称。为了显示:

当“代码”位于路由数据中时,我想获得与不存在时注入的不同依赖关系。
我知道可以使用.When()方法进行条件绑定,但是我不确定如何从那里获取路由数据。我也可以根据调用它的区域来执行此操作,但是在我的实例中这不是可取的(我认为我们可以在其他区域使用该代码)
这可能吗?
我的NHibernate会话管理设置如下:
protected MvcApplication()
{
BeginRequest += delegate
{
NHibernateSessionManager.Instance.OpenSession();
};
EndRequest += delegate
{
NHibernateSessionManager.Instance.CloseSession();
};
}
Run Code Online (Sandbox Code Playgroud)
当我需要保存到数据库时,我创建了一个如下所示的ActionFilterAttribute:
public class TransactionAttribute:ActionFilterAttribute {private ITransaction _currentTransaction;
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
_currentTransaction = NHibernateSessionManager.Instance.CurrentSession.Transaction;
_currentTransaction.Begin();
}
public override void OnActionExecuted(ActionExecutedContext filterContext)
{
if (_currentTransaction.IsActive)
{
if (filterContext.Exception == null)
_currentTransaction.Commit();
else
{
_currentTransaction.Rollback();
}
}
_currentTransaction.Dispose();
}
}
Run Code Online (Sandbox Code Playgroud)
然后我可以将[Transaction]添加到我的action方法中.这似乎适用于初始测试,但我尝试在HttpWebRequest使用多次从另一个应用程序调用一个动作方法,我遇到了问题.使用Fiddler进行测试我设置了一个POST请求,然后快速连续关闭它们,它显示以下内容:

红色是我认为与线程有关的各种错误.
我的NHibernateSessionManager使用HTtpContext来存储会话,如下所示:
public ISession CurrentSession
{
get { return (ISession)HttpContext.Current.Items["current.session"]; }
set { HttpContext.Current.Items["current.session"] = value; }
}
Run Code Online (Sandbox Code Playgroud)
因此,为了修复它,我将我的事务代码移动到我的BeginRequest和EndRequest方法中 - 然后我可以连续启动堆.
我的问题是 …
我为 Revit Structure API 创建了许多插件。每个工具都必须有一个实现 IExternalCommand 接口的类。
在最新版本的 Revit 中,为了让您的工具正常工作,您需要在实现该接口的类上拥有两个属性:
[再生(RegenesisOption.Manual)] [事务(TransactionMode.Automatic)]
括号中的值可以改变,但那里一定有东西。我经常发现自己忘记添加属性,然后在运行时它会崩溃。Visual Studio 2010 中是否有任何方法可以添加编译器警告或错误,指出如果您的类实现该接口,则它必须具有这两个属性?如果有帮助的话我有磨刀器。
有人能指出我正确的方向吗?
我刚开始使用Nant进行构建和测试.我想让它在失败时更改命令提示文本的颜色(或背景),以便轻松注意.
Windows上命令提示符中的命令为"颜色4",将其更改为红色,将颜色7更改为白色.
如何在构建脚本中运行,echo不起作用,exec不起作用(虽然可能使用exec错误).我宁愿不必运行perl等只是为了做一些在标准命令提示符窗口中轻松完成的事情.
有谁知道如何做到这一点?
我是犀牛模拟的新手,刚刚开始使用这个项目.
我正在测试一些调用外部方法的代码来获取IEnumerable的'Project',我有一个接口,以便我可以存根/模拟它.
在我的单元测试开始时测试一些迭代的代码(或调用Count(),两者都导致错误)IENumerable,我设置了一个存根实现
IJobProcess stub = MockRepository.Stub<IJobProcess>();
SetupResult.For(stub.CheckTeamMeetingInLastMonth(null)).IgnoreArguments().Return(true);
SetupResult.For(stub.GetOutstandingActions(null)).IgnoreArguments().Return(
new List<ProjectActionsDomain.DomainObjects.ProjectAction>()
);
Run Code Online (Sandbox Code Playgroud)
然而,这导致:
PmqccFormTests.GetFlagsReturnsIncompleteFlagWhenIncomplete : FailedSystem.InvalidOperationException : Previous method 'IEnumerator.MoveNext();' requires a return value or an exception to throw.
at Rhino.Mocks.Impl.RecordMockState.AssertPreviousMethodIsClose()
at Rhino.Mocks.Impl.RecordMockState.MethodCall(IInvocation invocation, MethodInfo method, Object[] args)
at Rhino.Mocks.MockRepository.MethodCall(IInvocation invocation, Object proxy, MethodInfo method, Object[] args)
at Rhino.Mocks.Impl.RhinoInterceptor.Intercept(IInvocation invocation)
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at System.Linq.Enumerable.Count(IEnumerable`1 source)
at PmqccDomain.DomainObjects.PmqccForm.GetFlags() in PmqccForm.cs: line 387
at PmqccUnitTests.PmqccFormTests.GetFlagsReturnsIncompleteFlagWhenIncomplete() in PmqccFormTests.cs: line 426
Run Code Online (Sandbox Code Playgroud)
但是,如果我将其更改为
IJobProcess mock = MockRepository.GenerateMock<IJobProcess>();
mock.Expect(x => x.GetOutstandingActions(null)).IgnoreArguments().Return(
new List<ProjectActionsDomain.DomainObjects.ProjectAction>());
mock.Expect(x => x.CheckTeamMeetingInLastMonth(null)).IgnoreArguments().Return(true); …Run Code Online (Sandbox Code Playgroud) 我想每5秒在mapview上更新一些注释的图像,但是我不想删除它们并将它们重新添加到地图中,因为这会导致它们"闪烁"或刷新,(即消失然后重新出现) .我希望它是无缝的.
我尝试过以下方法:
//get the current icon
UserAnnotation *annotation = [self GetUserIconWithDeviceId:deviceId];
//make a new annotation for it
UserAnnotation *newAnnotation = [[UserAnnotation alloc]
initWithCoordinate: userCoordinates
addressDictionary:nil];
newAnnotation.title = name;
newAnnotation.userDeviceId = deviceId;
NSInteger ageIndicator = [[userLocation objectForKey: @"ageIndicator"] integerValue];
newAnnotation.customImage = [UserIconHelpers imageWithAgeBorder:ageIndicator FromImage: userImage];
//if its not there, add it
if (annotation != nil){
//move it
//update location
annotation.coordinate = userCoordinates;
//add new one
[self.mapView addAnnotation: newAnnotation];
//delete old one
[self.mapView removeAnnotation: annotation];
} else {
//just addd the …Run Code Online (Sandbox Code Playgroud) 快速提问,我在Twitter开发中心找不到这些信息.
在推文的对象上,在用户部分有'favourites_count',这究竟是什么意思?他们这些推特有多少推文有优惠?或者也许他们的推文中有多少人受到青睐?或者是别的什么?
asp.net-mvc ×2
c# ×2
colors ×1
command-line ×1
httpcontext ×1
ios ×1
mapkit ×1
nant ×1
nhibernate ×1
ninject ×1
objective-c ×1
revit-api ×1
rhino-mocks ×1
twitter ×1