我正在尝试将SimpleInjector与WebFormsMvp结合起来.
为了方便DI WebFormsMvp提供了IPresenterFactory界面.
它包含Create提供要解析的演示者类型和视图实例的方法.
我需要注入的视图实例进入了一个构造的主持人.
演示者还具有需要由容器创建的其他依赖项.
这是我到目前为止所得到的,但它并不理想.这个问题
的正确解决方案是什么?
Presenter构造函数:
public FooPresenter(IFooView view, IClientFactory clientFactory) : base(view)
Run Code Online (Sandbox Code Playgroud)
厂:
public class SimpleInjectorPresenterFactory : IPresenterFactory
{
private readonly Container _container;
private IView _currentView;
public SimpleInjectorPresenterFactory()
{
_container = new Container();
Func<Type, bool> isIView =
type => typeof(IView).IsAssignableFrom(type);
_container.ResolveUnregisteredType += (s, e) => {
if …Run Code Online (Sandbox Code Playgroud) 假设我有两个我想要映射的对象:
// Domain objects
public class MyDomainObject
{
public string SimpleText { get; set; }
public int SimpleNumber { get; set; }
public MySubObject ComplexValue { get; set; }
}
public class MySubObject
{
public int Id { get; set; }
public string Name { get; set; }
}
// DTOs
public class MyDto
{
public string SimpleText { get; set; }
public int SimpleNumber { get; set; }
public int ComplexValueId { get; set; }
public string ComplexValueName { …Run Code Online (Sandbox Code Playgroud) 我尝试添加记录,以饰有一个属性的方法使用Spring.Net AOP的.
第1步:引用'Spring.Core','Spring.Aop','Common.Logging'
第2步:建议:
using AopAlliance.Intercept;
namespace MyApp.Aspects
{
public class LoggingAdvice : IMethodInterceptor
{
public object Invoke(IMethodInvocation invocation)
{
//todo: log started
object rval = invocation.Proceed();
return rval;
//todo: log finished
}
}
}
Run Code Online (Sandbox Code Playgroud)
第3步:创建属性:
using System;
namespace MyApp.Aspects
{
public class LoggingAttribute : Attribute
{
}
}
Run Code Online (Sandbox Code Playgroud)
第4步:编辑web.config
<configuration>
<configSections>
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core" />
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
</sectionGroup>
</configSections>
<spring>
<context>
<resource uri="config://spring/objects" />
</context>
<objects xmlns="http://www.springfrmework.net"> …Run Code Online (Sandbox Code Playgroud) 我有一个方法检查,如果一个字符串是一个有效的十六进制字符串:
public bool IsHex(string value)
{
if (string.IsNullOrEmpty(value) || value.Length % 2 != 0)
return false;
return
value.Substring(0, 2) == "0x" &&
value.Substring(2)
.All(c => (c >= '0' && c <= '9') ||
(c >= 'a' && c <= 'f') ||
(c >= 'A' && c <= 'F'));
}
Run Code Online (Sandbox Code Playgroud)
规则是:
表达式必须由偶数个十六进制数字组成(0-9,AF,af).
字符0x必须是表达式中的前两个字符.
我敢肯定它可以用更清洁,更有效的方式重写正则表达式.
你可以帮帮我吗?
给出以下内容:
- 起点(坐标)
- 角度(度)
- 速度
..我想计算给定的轨迹.
例如,对于下面的图像,速度为1:(10,10)(9,9)(8,8)(7,7)..
它应该能够向各个方向移动.
我怎么计算呢?

.net ×4
c# ×3
angle ×1
asp.net-mvc ×1
automapper ×1
geometry ×1
hex ×1
mapping ×1
math ×1
regex ×1
spring-aop ×1
spring.net ×1
webformsmvp ×1