我总是看到人们总是在谈论使用像Ninject,Unity,Windsor这样的框架来做依赖解析器和注入.以下代码为例:
public class ProductsController : ApiController
{
private IProductRepository _repository;
public ProductsController(IProductRepository repository)
{
_repository = repository;
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是:为什么我们不能简单地写为:
public class ProductsController : ApiController
{
private IProductRepository _repository;
public ProductsController() :this(null)
{}
public ProductsController(IProductRepository repository)
{
_repository = repository?? new ProductRepository();
}
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,似乎我们不需要任何框架,即使对于我们可以轻松模拟的单元测试.
那么这些框架的真正目的是什么?
提前致谢!
在.Net 4.X
,这个扩展方法是在System.Xml.XPath
.
但是,我想知道如何在.Net Core中找到/使用它?我有一个类库.
移植工具没有显示任何内容XPathSelectElement
.
或者.Net核心中的任何替代品?
非常感谢!
我是这个领域的新手.我已经使用更新3升级了VS2015.所以现在我已经安装了预览工具2的.Net Core 1.0.0.
然后我使用VS2015创建一个新的.Net Source项目(类库).我已将一些现有的.net 4.6.1代码复制到新位置并按预期编译错误.然后我使用"移植分析工具"(https://docs.microsoft.com/en-us/dotnet/articles/core/porting/index)进行比较,确实给出了一些如何在.Net中使用新方法的建议.核心.
但是仍然有很少的类缺失并且无法编译,比如'TypeDescriptor'或'NullableConverter'等.然后我用Google搜索并且来自Github的人说他们已经添加了这些功能但我仍然不确定为什么我仍然会遇到编译错误.
我还注意到我的类库项目有一个project.json文件:
"frameworks": {
"netstandard1.6": {
"imports": "dnxcore50"
}
}
Run Code Online (Sandbox Code Playgroud)
我发现如果我删除'netstandard1.6',但改为:
"frameworks": {
"net461": {}
}
Run Code Online (Sandbox Code Playgroud)
所有的编译错误都消失了,但我可以猜测它不再是.Net核心项目了,更有可能作为标准的.Net 4.6.1项目.
所以基本上我想问:
为什么Github的开发人员说已经修复但我仍然无法在我的项目中找到/编译这些类(例如TypeDescriptor:https://github.com/dotnet/corefx/issues/8262)?
一些示例还在project.json文件中的'frameworks'下放置'net461'和'netstard1.6'或'netcoreapp1.0'.这是为了什么目的?
如果我只使用'net461'作为唯一的框架,那么传统的.Net Framework 4.6.1项目似乎没什么区别.我对么?
非常感谢!
我已经读过,在C#中,我们无法在远程计算机上创建专用队列: 无法在远程服务器上创建专用消息队列
我的问题是:在PowerShell脚本中,我们可以这样做吗?这是我的示例脚本:
echo "Loading System.Messaging..."
[Reflection.Assembly]::LoadWithPartialName( "System.Messaging" )
$msmq = [System.Messaging.MessageQueue]
echo "Create the queue"
$qName = "remoteserver\private$\testqueue"
if($msmq::Exists($qName))
{
echo ($qName + " already exists ")
}
else
{
echo ($qName + " doesn't exists and now to create ......")
$q = $msmq::Create( $qName, $TRUE )
echo "Private queues has been created"
}
Run Code Online (Sandbox Code Playgroud)
它说"无效的队列路径名称".我也尝试过一些格式:FormatName:DIRECT=OS:remoteserver\private$\testqueue
结果是一样的.任何可能性?
.net-core ×2
asp.net-core ×2
c# ×2
asp.net ×1
dependencies ×1
nuget ×1
powershell ×1
windows ×1
xpath ×1