我有一个MVC2 n层应用程序(DAL,域,服务,MVC Web)使用DDD方法(域驱动设计),具有带存储库的域模型.我的服务层使用请求/响应模式,其中Request和Response对象包含DTO(数据传输对象)以将数据从一个层封送到下一个层,并且映射通过AutoMapper的帮助完成.我的问题是:DTO通常采用什么样的形状?它既可以嵌套/复杂的 DTO,还是严格来说是平面投影?或者可能两者兼而有之?另外,拥有平面DTO与更复杂/嵌套DTO的主要原因是什么?
例如,假设我有一个域,如下所示:
public class Employee
{
public string FirstName { get; set; }
public string LastName { get; set; }
public Company Company { get; set; }
}
public class Company
{
public string Name { get; set; }
public string Address { get; set; }
public string City { get; set; }
public string State { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我有三种不同的方法可以对Response对象进行建模.
选项1 - DRYest选项:
public class GetEmployeeResponse …Run Code Online (Sandbox Code Playgroud) 我注意到有两种不同的加载nib/xib文件的方法:
initWithNibName:bundle:方法loadNibNamed:owner:options:方法.有人可以解释这两者之间的差异,以及何时使用一个而不是另一个以及在什么情况下更合适?
例如,如果我从tableView:viewForHeaderInSection:方法中的nib文件加载自定义表节标题视图,我将使用哪一个?
或者,如果我从nib文件加载自定义表视图单元格,我会使用哪一个?
我们有一个自定义TraceListener(继承自System.Diagnostics.TraceListener),我们将其用于ASP.NET Web应用程序日志记录.它一直很好 - 没有问题.然后突然间它停止在我们的开发环境中工作(TraceListener.TraceEvent()停止激活).我们感到困惑的是它为什么停止工作.我们在代码中真正做出的唯一更改是添加了更多构建配置(Dev,Test,Stage,Prod).之前,它只有Debug和Release.
我注意到当我在本地测试使用Debug配置构建时,TraceListener.TraceEvent()被触发就好了.当我切换到另一个构建配置(即测试)时,则不再触发TraceEvent().这是我的网站.csproj文件的片段:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>TRACE;DEBUG;SkipPostSharp</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ExcludeGeneratedDebugSymbol>false</ExcludeGeneratedDebugSymbol>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Dev|AnyCPU'">
<OutputPath>bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Test|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>TRACE;DEBUG;SkipPostSharp</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ExcludeGeneratedDebugSymbol>false</ExcludeGeneratedDebugSymbol>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Stage|AnyCPU'">
<OutputPath>bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Prod|AnyCPU'">
<OutputPath>bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
<OutputPath>bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)
我不确定为什么切换构建配置似乎会关闭我们的日志记录.谁能指出我正确的方向?
我有多个视图相同NSURLRequest/NSURLConnection request.理想情况下,为了获得一些代码重用,我想要某种"代理"来完成创建/执行(异步)请求/连接,设置所有委托方法等所有基础工作. ,所以我不必NSURLConnection在每个视图中复制所有委托方法处理程序.首先,这种设计方法是否合理?第二,我将如何做这样的事情?
对于一些背景信息,我尝试了这个并让它"工作",但是,它似乎不是异步执行.我创建了一个Proxy.h/m文件,其中包含不同Web服务调用的实例方法(还包含NSURLConnection委托方法):
@interface Proxy : NSObject {
NSMutableData *responseData;
id<WSResponseProtocol> delegate;
}
- (void)searchForSomethingAsync:(NSString *)searchString delegate:(id<WSResponseProtocol>)delegateObj;
@property (nonatomic, retain) NSMutableData *responseData;
@property (assign) id<WSResponseProtocol> delegate;
@end
Run Code Online (Sandbox Code Playgroud)
WSResponseProtocol定义如下:
@protocol WSResponseProtocol <NSObject>
@optional
- (void)responseData:(NSData *)data;
- (void)didFailWithError:(NSError *)error;
@end
Run Code Online (Sandbox Code Playgroud)
要使用它,视图控制器只需要符合WSResponseProtocol协议,以捕获响应.进行Web服务调用是这样完成的:
Proxy *p = [[Proxy alloc] init];
[p searchForSomethingAsync:searchText delegate:self];
[p release];
Run Code Online (Sandbox Code Playgroud)
我可以提供更多代码,但剩下的可以假设.在打电话之前,我"开始动画"一个UIActivityIndicatorView微调器.但旋转器从不旋转.如果我只是将NSURLConnection委托方法直接放在视图控制器中,那么微调器就会旋转.所以,它让我觉得我的实现不是异步执行的.这里有什么想法/想法吗?
iphone asynchronous uiviewcontroller nsurlconnection nsurlrequest
我在尝试使用LINQ to SQL查询和映射到我的域对象DRY时遇到问题,而不会产生多次往返db的成本.鉴于这个例子:
var query1 = from x in db.DBProducts
select new MyProduct
{
Id = x.ProductId,
Name = x.ProductName,
Details = new MyProductDetail
{
Id = x.DBProductDetail.ProductDetailId,
Description = x.DBProductDetail.ProductDetailDescription
}
}
Run Code Online (Sandbox Code Playgroud)
该查询将对DB进行一次往返.大!但是,我看到的问题是,最终,我还将有一个'GetProductDetails'方法,它还需要做一些SAME"数据对象 - >域对象"映射,与上面非常类似.
为了减轻一些映射,我认为扩展部分数据对象类为我做映射可能是一个很酷的主意,如下所示:
public partial class DBProduct
{
MyProduct ToDomainObject()
{
return new MyProduct
{
Id = this.ProductId,
Name = this.ProductName,
Details = this.DBProductDetails.ToDomainObject()
};
}
}
public partial class DBProductDetail
{
MyProductDetail ToDomainObject()
{
return new MyProductDetail
{
Id = this.ProductDetailId,
Description = this.ProductDetailDescription
}; …Run Code Online (Sandbox Code Playgroud) 在 DynamoDB 中使用散列和范围/排序键创建复合键时,将创造性字符串值存储在排序键中似乎非常有用(例如“Details-123456-foo”,该值中的每个段对于那个记录)。在设计模式时,这些文档似乎也引导您朝这个方向前进。
也就是说,将排序键命名为通用名称是否有意义,例如“sortKey”或“rangeKey”而不是特定的名称(例如“createTimestamp”),以便您可以灵活地为同一哈希键存储各种数据,从而在使用带有散列/排序键的“查询”API 时保持快速数据访问?
我在通过此处的方法" 集中式cookie管理 "中概述的方法进行WCF服务调用时管理共享的auth cookie :http://megakemp.com/2009/02/06/managing-shared-cookies-in- WCF /
我已经建立了一个自定义的IClientMessageInspector,IEndpointBehavior,BehaviorExtensionElement,的作品.我的端点行为添加了一个消息检查器,如下所示:
public class MyEndpointBehavior : IEndpointBehavior
{
public void AddBindingParameters(ServiceEndpoint endpoint, System.ServiceModel.Channels.BindingParameterCollection bindingParameters)
{
}
public void ApplyClientBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.ClientRuntime clientRuntime)
{
// yuck.. Wish I had an instance of MyClientMessageInspector
// (which has the auth cookie already) so I could just inject that
// instance here instead of creating a new instance
clientRuntime.MessageInspectors.Add(new MyClientMessageInspector());
}
public void ApplyDispatchBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.EndpointDispatcher endpointDispatcher)
{
} …Run Code Online (Sandbox Code Playgroud) structuremap wcf dependency-injection wcf-client endpointbehavior
我似乎无法让UISearchBar从导航栏中的最左侧到最右侧定位.在 - (void)viewDidLoad方法中,我有以下代码:
UISearchBar *sb = [[UISearchBar alloc] initWithFrame:self.tableView.tableHeaderView.frame];
sb.delegate = self;
self.navigationItem.titleView = sb;
[sb sizeToFit];
[sb release];
Run Code Online (Sandbox Code Playgroud)
当你构建和运行时,乍一看它看起来很好.但是,仔细观察,你可以看出左边有一个边距/空格.这在宏观计划中并不是什么大不了的事,但当我点击搜索栏开始搜索时,我会将取消按钮设置为视图.因为搜索栏位于右侧略微位置,所以动画不稳定,取消按钮会像这样掉落: 链接文本
似乎UINavigationItem就像一个有三个单元格的表,在第一个和最后一个上面有一个我无法删除的填充 - 似乎也没有办法将它们"合并"在一起然后放置搜索栏那里.我知道这种外观是可能的,因为AppStore搜索在导航栏中有一个搜索栏,它一直到边缘.任何人都知道如何让搜索栏一直到边缘,所以我的滑入取消按钮动画将正常工作?
c# ×3
iphone ×3
asp.net-mvc ×2
asp.net ×1
asynchronous ×1
automapper ×1
aws-lambda ×1
aws-sdk ×1
cocoa-touch ×1
dto ×1
linq-to-sql ×1
logging ×1
msbuild ×1
nib ×1
nsurlrequest ×1
objective-c ×1
sql-server ×1
structuremap ×1
uisearchbar ×1
uitableview ×1
wcf ×1
wcf-client ×1