我正在使用带有实体框架的asp.net mvc并开始学习DDD.我正在研究包含调查的项目.这是我的域名模型:
public class Survey
{
public int? SurveyID { get; set; }
public string Name { get; set; }
public decimal MinAcceptanceScore { get; set; }
public int UserFailsCount { get; set; }
public IEnumerable<SurveyQuestion> Questions { get; set; }
public IEnumerable<Prize> Prizes { get; set; }
public IEnumerable<SurveyAttempt> UserAttempts { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我需要不同视图的不同部分调查,所以我创建了不同的ViewModel:
public class ShortSurveyViewModel
{
public int? SurveyID { get; set; }
public string Name { get; set; }
public int UserFailsCount { get; …Run Code Online (Sandbox Code Playgroud) asp.net-mvc domain-driven-design entity-framework repository-pattern viewmodel
我已切换到ASP.NET vNext beta6并开始尝试运行我的应用程序时收到以下异常:
Ninject.ActivationException: Error activating IOptions{MvcJsonOptions} using binding from IOptions{TOptions} to OptionsManager{TOptions}
A cyclical dependency was detected between the constructors of two services.
Activation path:
4) Injection of dependency IOptions{MvcJsonOptions} into parameter jsonOptions of constructor of type MvcJsonMvcOptionsSetup
3) Injection of dependency IConfigureOptions{MvcOptions} into parameter setups of constructor of type OptionsManager{MvcOptions}
2) Injection of dependency IOptions{MvcOptions} into parameter optionsAccessor of constructor of type ControllerActionDescriptorProvider
1) Request for IActionDescriptorProvider
Suggestions:
1) Ensure that you have not declared a …Run Code Online (Sandbox Code Playgroud) 我允许用户动态创建输入字段。对于每个输入字段,我想将其连接到不同的 mat-autocomplete,以便它们彼此独立工作。我在这里遇到了障碍,因为我无法动态创建将自动完成连接到输入的元素引用(此处为#auto)。我该如何实现这一目标?
<div
class="row"
*ngFor="let field of getControls('requestFields'); let i = index"
formArrayName="requestFields"
>
<ng-container [formGroupName]="i">
<div class="col-md-4">
<mat-form-field class="example-full-width">
<input
type="text"
placeholder="Name"
matInput
formControlName="reqName"
matAutocomplete="auto"
/>
<mat-autocomplete #auto="matAutocomplete">
<mat-option
*ngFor="let option of (filteredColumns | async)"
[value]="option"
>
{{ option }}
</mat-option>
</mat-autocomplete>
</mat-form-field>
</div>
<div class="col-md-2">
<div class="togglebutton">
<label>
<span>Optional</span>
<input type="checkbox" formControlName="reqOption" />
<span class="toggle"></span>
</label>
</div>
</div>
<div class="col-md-4">
<mat-form-field>
<input
matInput
formControlName="reqValidations"
placeholder="Validation"
type="text"
/>
</mat-form-field>
</div>
</ng-container>
</div>
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Ninject自动注册AutoMapper配置文件.为此,我需要实例化从AutoMapper.Profile继承的类型的对象,例如:
public class WordMapping : Profile
{
protected override void Configure()
{
Mapper.CreateMap<Datacontext.Entities.Word, Domain.Entities.Word>();
Mapper.CreateMap<Domain.Entities.Word, Datacontext.Entities.Word>();
}
}
Run Code Online (Sandbox Code Playgroud)
首先,我试图通过反射来做到这一点,它就像一个魅力:
var profileType = typeof(AutoMapper.Profile);
var profiles = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(a => a.GetTypes())
.Where(t => profileType.IsAssignableFrom(t) && t.GetConstructor(Type.EmptyTypes) != null)
.Select(Activator.CreateInstance)
.Cast<Profile>();
foreach (var profile in profiles)
{
Mapper.AddProfile(profile);
}
Run Code Online (Sandbox Code Playgroud)
但是当我尝试用Ninject做同样的事情时:
public class MappingModules : NinjectModule
{
public override void Load()
{
Kernel.Bind(scanner =>
{
scanner.FromAssembliesMatching("*")
.SelectAllClasses()
.InheritedFrom<AutoMapper.Profile>();
});
var profiles = Kernel.GetAll<Profile>();
foreach (var profile in profiles)
{
Mapper.AddProfile(profile);
}
}
} …Run Code Online (Sandbox Code Playgroud) 是否有一种简单的方法可以为IEnumerable的每个成员添加前缀或后缀?除了(输入是IEnumerable)之外,我无法找到方法:
var sb = new StringBuilder();
foreach (var str in inputs) {
str = sb.Append(prefix).Append(str).ToString();
sb.clear();
}
Run Code Online (Sandbox Code Playgroud)
但这不会让我回到str ...我觉得应该有更好的方法来做到这一点.
c# ×3
ninject ×2
angular5 ×1
asp.net ×1
asp.net-core ×1
asp.net-mvc ×1
automapper ×1
ienumerable ×1
prefix ×1
reflection ×1
string ×1
viewmodel ×1