我正在使用Simple Injector和ASP.NET MVC项目.我添加了SimpleInjector.Integration.Web.Mvc
nuget包.这会SimpleInjectorInitializer
在App_Start
文件夹中添加类并初始化DI.代码看起来像
public static void Initialize()
{
// Did you know the container can diagnose your configuration?
// Go to: https://simpleinjector.org/diagnostics
var container = new Container();
//Container configuration code
DependencyResolver.SetResolver(
new SimpleInjectorDependencyResolver(container));
}
Run Code Online (Sandbox Code Playgroud)
这样可以正确配置MVC控制器的DI.
我的问题是,如果我想在任何controller\class中获取容器的实例来手动解决某些依赖,我该怎么办呢.
我之前曾在AutoFac上工作,它有一个依赖接口IComponentContext
,可以注入任何需要手动执行任何分辨率的类.
更新:
这是一个场景.我的控制器使用的服务初始化取决于在控制器方法中传递的输入参数,因此在构造期间不能实例化依赖性.
我知道这对于DI来说有点反模式,但是在很少的地方需要它,因此注入DI容器是下一个最好的事情.简单的注入器样本应该使用静态变量来共享我想要避免的容器,并且通过SimpleInjectorInitializer
工作方式也是不可能的.
使用TFS搁置集的原因之一是代码审查,我不同意,但这是我当前项目中遵循的做法.我看到使用TFS搁置集的原因不是代码审查的好主意
有人可以提供一些指针,可以支持或反对 TFS搁置集审查方法,所以要么我对这种方法有信心,要么我可以提出不使用这种方法的案例?
使用ng-if与值或函数有什么区别吗?
ng-if="myvalue"
ng-if="myfunc()"
Run Code Online (Sandbox Code Playgroud)
更新(为了更好地理解我要求的原因)
<div class="navbar navbar-default navbar-static-top" data-ng-controller="NavController as nav">
<div class="container">
<ul class="nav navbar-nav">
<a data-ui-sref="home" class="navbar-brand"><i class="logo"></i> Angular Express</a>
<li ui-sref-active="active"><a data-ui-sref="home">Home</a></li>
</ul>
<ul class="nav navbar-nav navbar-right" data-ng-if="!nav.isAuthenticated()">
<li><a data-ui-sref="session.login">Log in</a></li>
<li><a data-ui-sref="session.signup">Sign up</a></li>
</ul>
<ul class="nav navbar-nav navbar-right" data-ng-if="nav.isAuthenticated()">
<li><i class="fa fa-user"></i> <span ng-bind="nav.isAuthenticated().username"></span> <a href="/api/auth/logout" data-ng-click="nav.logout()">Logout</a></li>
</ul>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
function NavController($rootScope, UserStorage){
var nav = this;
nav.isAuthenticated = function() {
UserStorage.get();
};
}
function UserLoginController($rootScope,$state, Users, UserStorage) {
var user = this;
user.data …
Run Code Online (Sandbox Code Playgroud) 我正在使用Angular JSON Http调用.同样当我发布这样的帖子请求时:
app.service('AjaxService', [ '$http','$q','$sce', function($http,$q,$sce) {
return {
getSearchResultsJSONP : function() {
var url="http://stage-sp1004e4db.guided.lon5.atomz.com/?searchType=globalsearch&q=this&sp_staged=1&callback=JSON_CALLBACK";
$sce.trustAsResourceUrl(url);
$http.jsonp(url)
.success(function(data) {
console.log("Data for default SNP call" ,data);
}).
error(function (data) {
console.log("request Failed ! ");
});
},
getSearchResult : function(searchText,url){
var defer = $q.defer();
$http({
url: url,
method: "GET",
params: {searchresInput: searchText}
}).then(function(data, status, header, config){
defer.resolve(data);
}).then(function(data, status, header, config){
defer.reject(data);
});
return defer.promise;
}
};
}]);
Run Code Online (Sandbox Code Playgroud)
我可以看到网络中的数据和响应是200 OK状态.
但是在完整的代码运行期间我收到错误:
Uncaught TypeError: Cannot read property 'parentElement' of undefined
at checklistFunc …
Run Code Online (Sandbox Code Playgroud) 对于我们的.Net应用程序,我们已将许可组件集成到应用程序中 在应用程序代码中,我们验证许可证,并在此基础上我们需要启用/禁用某些功能.例如,如果用户具有试用许可证,则他们只能访问应用程序的特定部分,而付费用户可以访问任何部分.我需要帮助决定设计,以便影响最小.我不想在if..else语句中撒上代码.请与我分享一些实现这一目标的最佳方法.