如何使用ASP.NET Core MVC内置依赖注入框架手动解析类型?
设置容器很容易:
public void ConfigureServices(IServiceCollection services)
{
// ...
services.AddTransient<ISomeService, SomeConcreteService>();
}
Run Code Online (Sandbox Code Playgroud)
但是如何在ISomeService不进行注射的情况下解决?例如,我想这样做:
ISomeService service = services.Resolve<ISomeService>();
Run Code Online (Sandbox Code Playgroud)
没有这样的方法IServiceCollection.
使用新的Azure SQL数据库层结构,监视数据库"DTU"用法以了解是升级还是降级到另一层似乎很重要.
在阅读Azure SQL数据库服务层和性能级别时,它仅讨论使用CPU,数据和日志百分比使用情况进行监控.
但是,当我添加新指标时,我还有一个DTU百分比选项:

我在网上找不到这个.这基本上是其他DTU相关指标的摘要吗?
它最近向我指出,各种LINQ的扩展方法(如Where,Select等)返回IEnumerable<T>,恰巧也有IDisposable.以下评估结果True
new int[2] {0,1}.Select(x => x*2) is IDisposable
Run Code Online (Sandbox Code Playgroud)
我是否需要处理Where表达式的结果?
每当我打电话给一个方法返回时IEnumerable<T>,我(可能)接受在我完成它时调用dispose的责任吗?
我需要公开一个类实例的" is mapped? "状态.结果由基本检查确定.它不是简单地暴露字段的值.我不确定是否应该使用只读属性或方法.
只读属性:
public bool IsMapped
{
get
{
return MappedField != null;
}
}
Run Code Online (Sandbox Code Playgroud)
方法:
public bool IsMapped()
{
return MappedField != null;
}
Run Code Online (Sandbox Code Playgroud)
在我们的Startup课程中,我配置了以下auth服务器选项:
OAuthAuthorizationServerOptions OAuthServerOptions = new OAuthAuthorizationServerOptions()
{
AllowInsecureHttp = true,
TokenEndpointPath = new PathString("/api/v1/token"),
AccessTokenExpireTimeSpan = TimeSpan.FromDays(1),
Provider = new SimpleAuthorizationServerProvider()
};
Run Code Online (Sandbox Code Playgroud)
在此之后,我们应该使用哪个选项来实际启用承载身份验证?互联网上似乎有两种变体.
选项1:
app.UseOAuthAuthorizationServer(OAuthServerOptions);
app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());
Run Code Online (Sandbox Code Playgroud)
选项2:
app.UseOAuthBearerTokens(OAuthServerOptions);
Run Code Online (Sandbox Code Playgroud)
我对它们进行了测试,结果是一样的.
这些选项有什么区别?我们什么时候应该使用哪个?
owin katana asp.net-identity asp.net-web-api2 asp.net-identity-2
我的存储库处理并为丰富的域模型提供持久性.我不想将贫血的Entity Framework数据实体暴露给我的业务层,所以我需要一些在它们之间进行映射的方法.
在大多数情况下,从数据实体构造域模型实例需要使用参数化构造函数和方法(因为它很丰富).它不像属性/字段匹配那么简单.AutoMapper可用于相反的情况(映射到数据实体),但不能用于创建域模型.
以下是我的存储库模式的核心.
在EntityFrameworkRepository类的工作有两个泛型类型:
TDomainModel:丰富的域模型TEntityModel:实体框架数据实体定义了两种抽象方法:
ToDataEntity(TDomainModel):转换为数据实体(for Add()和Update()方法)ToDomainModel(TEntityModel):构建域模型(用于Find()方法). 这些方法的具体实现将定义所讨论的存储库所需的映射.
public interface IRepository<T> where T : DomainModel
{
T Find(int id);
void Add(T item);
void Update(T item);
}
public abstract class EntityFrameworkRepository<TDomainModel, TEntityModel> : IRepository<TDomainModel>
where TDomainModel : DomainModel
where TEntityModel : EntityModel
{
public EntityFrameworkRepository(IUnitOfWork unitOfWork)
{
// ...
}
public virtual TDomainModel Find(int id)
{
var entity = context.Set<TEntityModel>().Find(id);
return ToDomainModel(entity);
}
public virtual void …Run Code Online (Sandbox Code Playgroud) .net domain-driven-design entity-framework repository-pattern onion-architecture
我创建了一个Attribute名为的类RelatedPropertyAttribute:
[AttributeUsage(AttributeTargets.Property)]
public class RelatedPropertyAttribute: Attribute
{
public string RelatedProperty { get; private set; }
public RelatedPropertyAttribute(string relatedProperty)
{
RelatedProperty = relatedProperty;
}
}
Run Code Online (Sandbox Code Playgroud)
我用它来表示类中的相关属性.我将如何使用它的示例:
public class MyClass
{
public int EmployeeID { get; set; }
[RelatedProperty("EmployeeID")]
public int EmployeeNumber { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我想使用lambda表达式,以便我可以将强类型传递给我的属性的构造函数,而不是"魔术字符串".这样我可以利用编译器类型检查.例如:
public class MyClass
{
public int EmployeeID { get; set; }
[RelatedProperty(x => x.EmployeeID)]
public int EmployeeNumber { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我以为我可以使用以下内容,但编译器不允许这样做:
public RelatedPropertyAttribute<TProperty>(Expression<Func<MyClass, TProperty>> propertyExpression)
{ ... } …Run Code Online (Sandbox Code Playgroud) 我想使用内部版本号附加我们的应用程序版本.例如,1.3.0.201606071.
在AssemblyInfo中设置它时,我得到以下编译错误:
错误CS7034指定的版本字符串不符合所需的格式 - 主要[.minor [.build [.revision]]]
装配信息:
[assembly:System.Reflection.AssemblyFileVersionAttribute("1.0.0.201606071")]
[assembly:System.Reflection.AssemblyVersionAttribute("1.0.0.201606071")]
[assembly:System.Reflection.AssemblyInformationalVersionAttribute("1.0.0.201606071")]
Run Code Online (Sandbox Code Playgroud)
为什么会这样?
项目A引用项目B,项目B引用外部DDL(使用NuGet恢复).DLL应该被复制到 Project A的bin文件夹(以及 Project B的DLL):

在我的例子中,当运行项目A时,我得到以下异常抛出:
无法加载文件或程序集'PostSharp,Version = 3.2.18.0,Culture = neutral,PublicKeyToken = b13fd38b8f9c99d7'或其依赖项之一.该系统找不到指定的文件.
DLL未被复制到项目A的bin中.来自Project B的所有其他外部引用都被正确复制,这对我来说很困惑.
Copy Local对于所涉及的所有引用,都设置为true.例:

我该怎么做呢?
注意:使用Visual Studio 2013.
理想情况下,我想使用构建变量(在VSTS上)配置我们的Azure Web App应用程序设置,例如:
我们使用Powershell脚本执行发布任务.要设置应用程序设置,可以使用以下脚本:
param($websiteName, $appSettings)
Set-AzureWebsite -Name $websiteName -AppSettings $appSettings
Run Code Online (Sandbox Code Playgroud)
我可以手动将这些构建变量传递给Powershell脚本构建任务,如下所示:
PrepareAppSettings.ps1 -websiteName "MyWebApp" -appsettings @{"MyConnectionString" = $(MyConnectionString);"MyRandomService" = $(MyRandomService);"MyRandomServiceClient"=$(MyRandomServiceClient);"MyRandomServicePassword"=$(MyRandomServicePassword)}
Run Code Online (Sandbox Code Playgroud)
有没有办法将所有构建变量传递给脚本而不必在哈希表中显式指定每个变量?
c# ×6
.net ×5
asp.net-core ×1
assemblyinfo ×1
attributes ×1
azure ×1
azure-devops ×1
class ×1
dispose ×1
ienumerable ×1
katana ×1
linq ×1
methods ×1
owin ×1
powershell ×1
properties ×1
reflection ×1
solution ×1
tfs ×1