我有一个静态类来设置Autofac注册,其方法在Application_Start中调用。像这样:
public static class RegisterAutofac
{
public static void Setup()
{
var config = GlobalConfiguration.Configuration;
var builder = new ContainerBuilder();
//Do registration here...
var container = builder.Build();
var resolver = new AutofacWebApiDependencyResolver(container);
GlobalConfiguration.Configuration.DependencyResolver = resolver;
}
}
Run Code Online (Sandbox Code Playgroud)
到目前为止,我还没有找到处理容器的示例。
这是否足够?还是应该返回容器,然后在Global.asax的Dispose方法中处置容器?
我有一个模型类:
public class MyModel() { //properties here... }
Run Code Online (Sandbox Code Playgroud)
我想验证一个MyModel对象列表。所以我创建了这个验证器:
class MyModelListValidator : AbstractValidator<List<MyModel>>
{
public MyModelListValidator ()
{
RuleFor(x => x)
.SetCollectionValidator(new MyModelValidator())
.When(x => x != null);
}
private class MyModelValidator : AbstractValidator<MyModel>
{
public MyModelValidator()
{
//MyModel property validation here...
}
}
}
Run Code Online (Sandbox Code Playgroud)
但上面的不起作用。另一种方法是创建一个类,如:
public class MyModelList()
{
public List<MyModel> Items { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
这会奏效。
但是有没有办法在不使用这个额外类的情况下做到这一点?
我正在将我的 ASP.Net 应用程序迁移到 ASP.Net 核心,我拥有的一项功能是我的所有控制器都继承自我所做的基本控制器:
protected override void Initialize(HttpControllerContext controllerContext)
{
base.Initialize(controllerContext);
string token = controllerContext.Request.Properties["token"] as string;
user = UserCache.Get(token);
//Called by derived controllers
//to set their repository user
SetInfo();
}
Run Code Online (Sandbox Code Playgroud)
我需要将上面的代码移动到中间件吗?中间件是否允许我设置调用控制器的 SetInfo() 方法?
我创建了一个空的空白 ionic 应用程序(没有电容器),添加了cordova 插件并安装了 google-plus 包。
在packages.json 的devDependecies 部分中,我有:
"@angular-devkit/build-angular": "^0.1100.1",
"@angular-devkit/core": "^11.0.1",
"@angular/cli": "~10.0.5",
"@angular/compiler": "~10.0.0",
"@angular/compiler-cli": "~10.0.0",
"@angular/language-service": "~10.0.0",
Run Code Online (Sandbox Code Playgroud)
我通过执行以下操作继续构建应用程序:
离子科尔多瓦构建 android --prod --release --verbose
但我得到了例外:
\dev\myapp\node_modules@angular\cli\lib\cli\index.js C:\dev\myapp\node_modules@angular\cli\lib\init.js C:\dev\myapp\node_modules@angular\cli\bin \ng 有关详细信息,请参阅“C:\Users\xyz\AppData\Local\Temp\ng-EHBnHs\angular-errors.log”。[错误] 运行子进程 ng 时出错。
我尝试了各种 SO 答案,例如清理缓存、更新、重新安装等……但我仍然收到此错误:
有什么办法可以修复这个错误?
我有一个名为'MyApp.DAL'的程序集,它包含和接口IRepository.我还有另一个程序集"MyApp.Repository",其中我有一些从IRepository派生的更复杂的存储库.
我还有服务层'MyApp.Service',其中一些服务引用来自'MyApp.Respository'的复杂存储库以及来自'MyApp.DAL'的简单接口IRepository.
这是界面:
public interface IRepository<T> where T : class
{
void Add(T entity);
void Update(T entity);
void Delete(T entity);
T GetById(long Id);
}
Run Code Online (Sandbox Code Playgroud)
这是实施:
public abstract class Repository<T> : IRepository<T> where T : class
{
private MyContext dataContext;
private readonly IDbSet<T> dbset;
protected Repository(IDatabaseFactory databaseFactory)
{
DatabaseFactory = databaseFactory;
dbset = DataContext.Set<T>();
}
protected IDatabaseFactory DatabaseFactory
{
get;
private set;
}
protected MyContext DataContext
{
get { return dataContext ?? (dataContext = DatabaseFactory.Get()); }
}
public virtual void Add(T …Run Code Online (Sandbox Code Playgroud) 我有以下模型(和相应的DTO):
public class Link
{
public int Id {get; set;}
public int FirstLinkId {get; set;}
public int SecondLinkId {get; set;}
public virtual Link FirstLink {get; set;}
public virtual Link SecondLInk {get; set;}
}
public class OtherObject
{
public int Id {get; set;}
public int LinkId {get; set;}
public string Name {get; set;}
public virtual Link Link {get; set;}
}
Run Code Online (Sandbox Code Playgroud)
在我的场景中,我可以有一个Link对象,其中FirstLink和/或SecondLink可以为null,对其他对象的引用或对同一对象的引用.
现在我想OtherObject使用EF从数据库加载实体.我加载实体本身以及Link与之关联的对象.这完全由EF完成.
在这个特定的情况下,两个FirstLink和SecondLink是相同的Link,因此,从模型自动映射到DTO它时,只是不断映射被遗忘.
我的映射是:
Mapper.CreateMap<OtherObject, …Run Code Online (Sandbox Code Playgroud) 在以下代码段中,如何将对象作为参数传递给脚本中的方法?
var c = new MyAssembly.MyClass()
{
Description = "test"
};
var code = "using MyAssembly;" +
"public class TestClass {" +
" public bool HelloWorld(MyClass c) {" +
" return c == null;" +
" }" +
"}";
var script = CSharpScript.Create(code, options, typeof(MyAssembly.MyClass));
var call = await script.ContinueWith<int>("new TestClass().HelloWorld()", options).RunAsync(c);
Run Code Online (Sandbox Code Playgroud) 我创建了一个任务,分配了大多数属性(包括迭代)并保存了它.然而,它没有显示在积压或董事会中.
我已手动将其设置为"活动".但无济于事.
最初的任务是孩子接受另一项任务.父任务也在同一次迭代中(但没有显示)
这不是唯一没有出现在任何地方的工作项.
有什么理由吗?
编辑
例如,如果区域是,则任务和用户故事被添加到积压和董事会MyProject.如果该区域是"MyProject/Modules/Customers",则不会显示任务和用户故事.
为什么是这样?
我有一个 ASP.NET 项目 (NET6),我通过以下方式删除了 Docker 支持:
当我尝试发布该项目时,出现以下错误:
Visual Studio 容器工具需要 Docker Desktop。要获取它,请参阅https://go.microsoft.com/fwlink/?linkid=847268
“KillAppInsideContainer”任务意外失败。
我已经安装了适用于 Windows 的 Docker Desktop,但在发布时仍然出现以下错误:
“KillAppInsideContainer”任务意外失败。
找不到方法:“无效 Microsoft.VisualStudio.Containers.Tools.Shared.Functions.AzureFunctionsFeedDataProvider..ctor(Microsoft.VisualStudio.Containers.Tools.Common.Services.Logging.ILoggingService)”。
我是否缺少仍然引用 Docker 的其他设置/位置?
我需要获取一个带有 html 文档的嵌套 div,例如:
<div id="maindiv>
<div id='firstdiv'>
</div>
<div id="otherid">
<div id="anotherdiv"><div id="divid"></div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我需要获取 的内容anotherdiv。我不知道maindiv主文档中的anotherdiv深度以及maindiv.
目前我正在做:
var doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(content);
var main = doc.GetElementbyId("maindiv").InnerHtml;
doc.LoadHtml(main);
var another = doc.GetElementbyId("anotherdiv");
Run Code Online (Sandbox Code Playgroud)
这很好用。但是有没有更好的方法使用 XPath 来获取所需的 div 呢?
c# ×8
asp.net-core ×2
angular ×1
asp.net ×1
autofac ×1
automapper ×1
azure-devops ×1
cordova ×1
docker ×1
html ×1
roslyn ×1
xpath ×1