我正在开发 API 服务器(ASP.NET Core)。为了防止将来出现意大利面条式代码和其他讨厌的东西,我按照 Clean Architecture/CQRS(使用 MediatR)设计系统。
我正在考虑将 GraphQL 用于 API 而不是 REST(Hot Chocolate GraphQL)。在 HotChocolate GraphQL 的几个示例中,使用 GraphQL-EF 机制直接查询数据库。虽然这似乎是有益的,但我担心从长远来看这可能会使代码复杂化。数据库结构可能会发生变化等。在我看来,API 应该与存储库层保持分离。尽管需要做更多的工作,但我认为 GraphQL 应该与 CQRS 通信。
你的想法,请!
我试图了解ViewModels和Service类的实例化,并将其写入其他人.请在需要的地方更正/添加.
ViewModels和Services的实例化不是以最常见的方式完成的.它是用反射完成的.
在TipCalc中你有:
public class FirstViewModel : MvxViewModel
{
private readonly ICalculationService _calculationService;
public FirstViewModel(ICalculationService calculationService)
{
_calculationService = calculationService;
}
...
}
Run Code Online (Sandbox Code Playgroud)
和
public class App : Cirrious.MvvmCross.ViewModels.MvxApplication
{
public override void Initialize()
{
CreatableTypes()
.EndingWith("Service")
.AsInterfaces()
.RegisterAsLazySingleton();
...
}
}
Run Code Online (Sandbox Code Playgroud)
在Initialize()期间,设计为Service的接口和类(名称以Service结尾)使用反射以及接口名称和类名称(IPersonService和PersonService)进行配对.这稍后用于反向查找类的实例(查找表包含对服务类的单例实例的延迟引用.服务在null时创建.
public FirstViewModel(ICalculationService calculationService)引用CalculationService的实例.这是通过使用先前创建的查找表来完成的.
ViewModels的实例化是通过Mvx框架完成的.当"询问"MvxFramework实例化的ViewModel时,它将反映ViewModel并确定该类上的构造函数.如果有一个无参数构造函数,那么将使用它.如果存在带参数的构造函数且参数是服务类的接口,则该服务的(单例)实例将用作参数.
服务以类似的方式实例化; 他们的构造函数反映和参数实例化(单例).等等.
xamarin.ios xamarin.android windows-phone mvvmcross windows-store-apps
我正在使用MvvmCross.在库中,我看到了Mvx.Trace方法的用法,但没有输出到控制台/输出窗口.如何使用它?
ps我已经设置了编译器常量Trace = true
谢谢.
在我的PCL核心项目(WP8,Android,iOS,Xamarin,MvvmCross)中,我使用自定义属性.Type.GetCustomAttributes()扩展方法让我检查使用的属性.
使用PCL Profile104这很有效.但是因为我想使用async/await,我需要使用PCL Profile78(和.NET 4.5)
问题:似乎GetCustomAttributes()和Attributes属性在Profile78中不可用.为什么??
注意:我正在研究解决方法,方法是创建一个PCL Profile 104类库并包装GetCustomAttributes(),然后从我的PCL Profile78库中引用该库.然而,似乎不支持扩展方法...
示例代码:
public Pcl78Class()
{
Type t = this.GetType();
var attributes = t.Attributes;
var customAttributes = t.GetCustomAttributes(true);
// another weird thing: Why is VS CodeCompletion telling me it knows CustomAttributeExtensions class and methods?
//System.Reflection.CustomAttributeExtensions.GetCustomAttributes(t);
}
Run Code Online (Sandbox Code Playgroud)

c# xamarin.ios xamarin.android portable-class-library xamarin
xamarin.ios ×3
mvvmcross ×2
xamarin ×2
asp.net-core ×1
c# ×1
cqrs ×1
graphql ×1
hotchocolate ×1
mediatr ×1
mono ×1