我读过DDD书(Eric Evans),需要在演示中使用的程序应该转移到服务类.例如,BankAccountManagementService具有ChangeBankAccount,GetByAccountId ...方法.
但是,我需要封装一些属性的setter,以禁止从其他业务对象分配它们.由于C#没有友好的类,因此在服务的情况下不可能使用这种类型的封装.但是可以使用BankAccount业务对象的静态方法来完成它.
(1)如果因上述原因使用服务,您如何解决此限制?
编辑:其他问题
(2)为什么使用静态方法代替服务是不好的?我可以将它们放在单独的部分类文件中,以免将proc代码与实体代码混合.
提前致谢 :)
我通常以下列方式检查构造函数参数的空值:
public class SomeClass(SomeArgument someArgument)
{
if(someArgument == null) throw new ArgumentNullException("someArgument");
}
Run Code Online (Sandbox Code Playgroud)
但是说我有一个继承自另一个类的类:
public abstract class TheBase
{
public TheBase(int id)
{
}
}
public class TheArgument
{
public int TheId { get; set; }
}
public class TheInheritor : TheBase
{
public TheInheritor(TheArgument theArgument) : base(theArgument.TheId)
{
}
}
Run Code Online (Sandbox Code Playgroud)
有人现在构造一个这样的实例TheInheritor:
var theVar = new TheInheritor(null);
Run Code Online (Sandbox Code Playgroud)
我想不出一种方法可以null在base被调用之前检查(并抛出一个NullReferenceException).如果没有让TheBase构造函数接受TheArgument我的实例,我就无法看到如何进行这种理智检查.但是,如果TheArgument仅与之相关TheInheritor并且还有很多其他类继承自己TheBase呢?
有关如何解决这个问题的任何建议?
我有1个asp.net mvc应用程序和一些类库(核心,repo,服务,测试)的解决方案.
将此解决方案转换为azure需要哪些步骤?
我有一个用于网站的新设计的photoshop psd文件(用PS-CS4打开),我想分析使用的渐变.我找到了负责渐变的图层,在混合选项下我找到了使用的渐变 - 但我错过了渐变开始和结束的确切RGB值.任何人都可以帮我找到这些价值观?
我必须更新Symfony中的多个列,但我无法找到解决方案......所以,我想这样做:
$q = Doctrine_Query::create()
->update('WebusersTable q')
->set('q.login_name','?','John')
->where('q.webuser_id=?',1)
->execute();
Run Code Online (Sandbox Code Playgroud)
好的,这有效,但我必须用几个列来做.我试过这样的东西,但它不起作用:
$q = Doctrine_Query::create()
->update('WebusersTable q')
->set('q.login_name,q.name','?','kaka,pisa')
->where('q.webuser_id=?',1)
->execute();
Run Code Online (Sandbox Code Playgroud) 我想知道asp.net mvc 2中是否存在一种方法,在一个proprety上有多个正则表达式.例如 :
[RegularExpression("[^0-9]", ErrorMessageResourceName = ValidationMessageResourceNames.OnlyDigits, ErrorMessageResourceType = typeof(ValidationMessages))]
[RegularExpression("[^<>]{2,}", ErrorMessageResourceName = ValidationMessageResourceNames.SpecialCharErrorCreateAccount, ErrorMessageResourceType = typeof(ValidationMessages))]
public string City { get; set; }
Run Code Online (Sandbox Code Playgroud)
这里的目标是两个有两个特定的错误消息,一个用于数字,另一个用于特殊字符,以及最小长度必须是2个字符的事实.
在此先感谢您的帮助或体验.
艾蒂安.
我有以下方法加载空白模板图像,在其上绘制相关信息并将其保存到另一个文件.我想稍微改变一下以实现以下目标:
我不想保存它,只需打印出来.这是我现有的方法:
public static void GenerateCard(string recipient, string nominee, string reason, out string filename)
{
// Get a bitmap.
Bitmap bmp1 = new Bitmap("template.jpg");
Graphics graphicImage;
// Wrapped in a using statement to automatically take care of IDisposable and cleanup
using (graphicImage = Graphics.FromImage(bmp1))
{
ImageCodecInfo jgpEncoder = GetEncoder(ImageFormat.Jpeg);
// Create an Encoder object based on the GUID
// for the Quality parameter category.
Encoder myEncoder = Encoder.Quality;
graphicImage.DrawString(recipient, new Font("Arial", 10, FontStyle.Regular), SystemBrushes.WindowText, new Point(480, 33)); …Run Code Online (Sandbox Code Playgroud) 我需要创建一个shell脚本来执行此操作:
我已经完成了第4步shell脚本.现在我必须逐一完成这4个步骤.我想创建一个脚本并完成所有操作.那可能吗?如何将数据从一台主机传输到我的主机?
我想也许db文件不是必需的.
注意:我必须ssh到另一台主机才能使用sqlplus.它是唯一一个拥有访问数据库权限的主机.
我正在使用Jaxb2Marshaller通过spring @ResponseBody注释来编组Java bean.对于JSON编组工作正常.但对于xml,我不断得到HTTP 406响应.Jaxb2Marshaller类中的一点点挖掘显示它为有界类检查@XmlRootElement(参见下面的代码片段).
从xsd生成java代码时,我的pojo不包含@XmlRootElement,并且AnnotationMethodHandlerAdapter未识别正确的消息转换器,最终导致406.
我没有从xsd自动生成java代码,而是创建了自己的pojo类并使用了@XmlRootElement.然后编组工作正常.
我想理解为什么让@XmlRootElement检查有界类很重要.或者在xsd中将元素指定为@XmlRootElement的任何方法.
Jaxb2Marshaller的代码片段:
public boolean supports(Class clazz) {
return supportsInternal(clazz, true);
}
private boolean supportsInternal(Class<?> clazz, boolean checkForXmlRootElement) {
if (checkForXmlRootElement && clazz.getAnnotation(XmlRootElement.class) == null) {
return false;
}
if (clazz.getAnnotation(XmlType.class) == null) {
return false;
}
if (StringUtils.hasLength(getContextPath())) {
String className = ClassUtils.getQualifiedName(clazz);
int lastDotIndex = className.lastIndexOf('.');
if (lastDotIndex == -1) {
return false;
}
String packageName = className.substring(0, lastDotIndex);
String[] contextPaths = StringUtils.tokenizeToStringArray(getContextPath(), ":");
for (String contextPath : contextPaths) {
if (contextPath.equals(packageName)) { …Run Code Online (Sandbox Code Playgroud)