按照我在这个线程中给出的建议[ Ninject UOW模式,用户通过身份验证后的新ConnectionString我现在明白我不应该使用以下行...
var applicationConfiguration =
(IApplicationConfiguration)
DependencyResolver.Current.GetService(typeof(IApplicationConfiguration));
Run Code Online (Sandbox Code Playgroud)
......作为服务定位器是一种反模式.
但是在以下过程的情况下,如何实例化实现" IApplicationConfiguration "的具体对象,以便我可以使用该对象获取未知用户角色名称,或者使用它来分配我的原则的" ApplicationConfiguration "属性?
Global.asax中
public class MvcApplication : NinjectHttpApplication
{
/// <summary>
/// Handles the PostAuthenticateRequest event of the Application control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
protected void Application_PostAuthenticateRequest(Object sender, EventArgs e)
{
String[] roles;
var applicationConfiguration =
(IApplicationConfiguration)
DependencyResolver.Current.GetService(typeof(IApplicationConfiguration));
var identity = HttpContext.Current.User.Identity;
if (Request.IsAuthenticated)
{
roles = Roles.GetRolesForUser(identity.Name);
}
else
{
roles …Run Code Online (Sandbox Code Playgroud) c# dependency-injection anti-patterns ninject service-locator
请问任何人都可以建议如何在AutoMapper中使用条件映射来根据现有的TARGET属性值从SOURCE对象映射TARGET对象中的值?
所以我的源类是:
public class UserDetails
{
public String Nickname { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我的目标类是:
public class ProfileViewModel
{
public Boolean NicknameIsVisible { get; set;
public String Nickname { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我想在TARGET中设置"Nickname"属性值以匹配SOURCE中的"Nickname"属性值,前提是目标属性"NicknameIsVisible"值已经设置为TRUE,否则我想设置TARGET"Nickname"属性值为空字符串.
我正在尝试这样的东西(不会编译)......
Mapper.CreateMap<UserDetails, ProfileViewModel>()
.ForMember(
destination => destination.Nickname,
option => option.
.MapFrom(
source => source.NicknameIsVisible ?
source.Nickname :
String.Empty)
);
Run Code Online (Sandbox Code Playgroud)
但是"NicknameIsVisible"不是我的SOURCE的属性,而是我的TARGET的属性.
顺便说一下,我的ProfileViewModel使用Owain Wragg的方法(http://consultingblogs.emc.com/owainwragg/archive/2010/12/22/automapper-mapping-from-multiple-objects.aspx)绑定到三个实体,它是另一个将值赋给"NicknameIsVisible"属性的实体.
任何人都可以建议使用正确的语法来解决这个问题吗?
我相信Visual Studio中有一个设置(或设置的组合),允许您在立即窗口(或输出窗口,我不记得哪个)中查看,在调试时加载的程序集的时间戳和名称.我曾经开启此功能,因为它对于查找性能问题区域非常有用.然而可悲的是,当VS最近决定解除我的所有窗口时没有任何理由,我不得不重置我的VS设置并且现在已经丢失了.
我无法找到我的生活,我已经开启了哪个设置.
任何帮助赞赏.
assemblies visual-studio-2008 visual-studio visual-studio-debugging output-window
虽然我可以在Web上找到(在网上)有关Visual Studio 2012数据库项目中的SQL脚本PreDeploy和PostDeploy 构建操作的大量信息,但我知道在部署时不编译或包含脚本,请任何人明确建议或指导我的一篇文章,它明确定义的细微之处和?NoneBuildCompile
我粗略的假设是这两个都将针对模式进行编译,但只会Build部署.它是否正确?
我想要的是正确的设置,以针对当前架构验证我的种子脚本(并导致无效架构结构上的构建错误),但不部署数据库发布或显示在架构比较会话中.
database-project sql-scripts buildaction visual-studio sql-server-data-tools
这可能是一个奇怪的问题,但有没有任何Windows API允许应用程序像映射驱动器或物理驱动器?例如,当您在Windows资源管理器中导航到"驱动器"时,应用程序将返回看似图像文件列表的内容.然后,当您单击图像文件时,应用程序将从数据库中提供图像.
是否可以使用visual studio Sql Server数据工具数据库项目为不同的发布配置文件部署不同的种子数据集?
我们知道您可以使用部署后脚本部署种子数据.我们知道您可以使用发布配置文件工具部署到不同的环境.我们不知道的是如何将不同的种子数据部署到不同的环境中.
我们为什么要这样做?
database-project visual-studio seeding publish-profiles sql-server-data-tools
在 SonarQube 的分析过程中,我们看到了许多此警告的示例
更改此条件,使其不总是评估为“假”;一些后续代码永远不会执行。
所以发生这种情况的一个例子是 - 对于给定的代码......
if (components?.ContainsKey(machineType) ?? false)
{
return components[machineType];
}
throw new ArgumentException($"There is no available configuration for {machineType}!");
Run Code Online (Sandbox Code Playgroud)
……我们得到……
我们正在使用 C# null 合并来快捷地进行空检查,以便提供components是一个字典,不是null,并且components 确实包含由machineType我们指定的键,然后我们返回components字典中machineType键的值。
否则,如果 components为 null,或者如果 Dictionary不包含键,则表达式计算为false并且我们不进入块并返回值,而是抛出异常。
请有人解释为什么 SonarQube 抱怨这个。如果我们重写它以使用空检查和&&ing的“老式”冗长风格,那么 SonarQube 就是一个快乐的兔子。
仅仅是 SonarQube 不了解??操作符吗?
还是我们只是在这样的语句中滥用?.or??运算符?
以下简单的实体...
public class MyEntity
{
[MaxLength(100)]
[Required]
public string Name { get; private set; }
}
Run Code Online (Sandbox Code Playgroud)
...是否可以读取正在装饰"Name"属性的数据注释并验证ChangeName方法中指定的值,以便ValidationResults可以连接到其他验证结果.我假设使用MethodInfo或PropertyInfo对象有些怎么样?
我有这个,但感觉非常笨拙.
public ValidationResult ChangeName(string value)
{
var property = GetType().GetProperty("Name");
var attribute = property.GetCustomAttributes(typeof(MaxLengthAttribute), true)[0] as MaxLengthAttribute;
if (attribute == null) return null; //yield break;
if (value.Length > attribute.Length)
{
return new ValidationResult(NameValidation.NameTooLong);
}
return null;
}
Run Code Online (Sandbox Code Playgroud)
我希望能够从我的验证器中的方法调用ChangeName(value),就像这样.
private IEnumerable<ValidationResult> ValidateMyEntity(MyEntityAddCommand command)
{
MyEntity myEntity = new MyEntity();
yield return myEntity.ChangeName(command.Name);
}
Run Code Online (Sandbox Code Playgroud)
到目前为止我读到的大多数内容都说数据注释是针对CRUD而不是DDD,但为什么不使用它们,因为它们是描述验证行为的好方法,它将与我的MVC视图模型上的数据注释验证一致.有没有更好或更简洁的方法可以做到这一点?所有建议都赞赏.
c# validation domain-driven-design command-pattern data-annotations
我的visual studio解决方案中的一个Web应用程序项目上面有一个蓝色感叹号图标,工具提示显示 The Web project <Project.Name.Here> has IIS configuration warnings
我在项目Properties页面或web.config文件中看不到任何内容.它从昨天开始,我假设重建VS并重新加载项目可能会摆脱警告,但事实并非如此.
这是什么以及如何解决这个问题?
谷歌今天早上没有帮助!
如果我有一个未知的数组作为System.Array,我如何找到它具有多少维?我在想可以被称为Array.GetDimensionCount()的东西
例如,如果我在System.Array类上构建扩展方法,并且想要验证arrayDimensionIndex不大于或等于数组具有的维数,那么我想抛出ArgumentOutOfRangeException
/// <summary>
/// Determines whether the value of the specified arrayIndex is within
/// the bounds of this instance for the specified dimension.
/// </summary>
/// <param name="instance">The instance of the array to check.</param>
/// <param name="arrayDimensionIndex">Index of the array dimension.</param>
/// <param name="arrayIndex">The arrayIndex.</param>
/// <returns></returns>
/// <exception cref="System.ArgumentOutOfRangeException">
/// If arrayDimensionIndex exceeds the number of dimesnions in the array.
/// </exception>
public static bool IsInBounds(this Array instance, int arrayDimensionIndex, int arrayIndex)
{
// Determine if this …Run Code Online (Sandbox Code Playgroud) c# ×5
arrays ×1
assemblies ×1
automapper ×1
buildaction ×1
conditional ×1
dimensions ×1
iis ×1
mapping ×1
ninject ×1
seeding ×1
sonarqube ×1
sql-scripts ×1
validation ×1
warnings ×1
web-project ×1
windows ×1