在Angular 1.x中,UI-Router是我的主要工具.通过返回"解析"值的承诺,路由器将在呈现指令之前等待承诺完成.
或者,在Angular 1.x中,null对象不会使模板崩溃 - 所以如果我不介意暂时不完整的渲染,我可以$digest在promise.then()填充最初为空的模型对象后使用它进行渲染.
在这两种方法中,如果可能的话,我宁愿等待加载视图,如果无法加载资源,则取消路由导航.这为我节省了"取消导航"的工作.编辑:注意这具体意味着这个问题要求Angular 2期货兼容或最佳实践方法来执行此操作,并要求尽可能避免使用"Elvis操作符"!因此,我没有选择那个答案.
但是,这两种方法都不适用于Angular 2.0.当然,有一个标准的解决方案计划或可用于此.有谁知道它是什么?
@Component() {
template: '{{cats.captchans.funniest}}'
}
export class CatsComponent {
public cats: CatsModel;
ngOnInit () {
this._http.get('/api/v1/cats').subscribe(response => cats = response.json());
}
}
Run Code Online (Sandbox Code Playgroud)
以下问题可能反映了相同的问题:加载数据PROMISE后的Angular 2渲染模板.请注意,问题中没有代码或接受的答案.
我正在开发Web Api,我决定使用自定义DependencyResolver.我引用了[Web API控制器的依赖注入]一文.到目前为止,依赖注入控制器的所有方面都运行良好.我的Owin启动类的配置代码片段
private void RegisterIoC(HttpConfiguration config)
{
_unityContainer = new UnityContainer();
_unityContainer.RegisterType<IAccountService, AccountService>();
.........
.........
config.DependencyResolver = new UnityResolver(_unityContainer);
}
Run Code Online (Sandbox Code Playgroud)
但是当Api第一次启动时,在UnityResolver的 GetService方法中抛出(但被捕获)一些ResolutionFailedException .这是异常消息
"Exception occurred while: while resolving.
Exception is: InvalidOperationException -
The current type, System.Web.Http.Hosting.IHostBufferPolicySelector,
**is an interface and cannot be constructed. Are you missing a type mapping?**"
Run Code Online (Sandbox Code Playgroud)
上述同样的异常抛出以下几种类型
System.Web.Http.Hosting.IHostBufferPolicySelector
System.Web.Http.Tracing.ITraceWriter
System.Web.Http.Metadata.ModelMetadataProvider
System.Web.Http.Tracing.ITraceManager
System.Web.Http.Dispatcher.IHttpControllerSelector
System.Web.Http.Dispatcher.IAssembliesResolver
System.Web.Http.Dispatcher.IHttpControllerTypeResolver
System.Web.Http.Controllers.IHttpActionSelector
System.Web.Http.Controllers.IActionValueBinder
System.Web.Http.Validation.IBodyModelValidator
System.Net.Http.Formatting.IContentNegotiator
Run Code Online (Sandbox Code Playgroud)
我知道抛出这些ResolutionFailedException是因为我没有在上面的类型的单位配置中提供映射.
现在这里是我的问题: -,如果我实现自定义统一DependencyResolver我需要定义上述类型的映射,如果需要定义它们对应的默认实现类型,或者是否有一些替代方法来实现DependencyResolver.我真的担心即使应用程序运行正常,但未能解决上述类型可能会导致严重问题. …
dependency-injection unity-container asp.net-web-api dependency-resolver
假设我有一个A依赖于项目的开发项目B- 该项目目前正在开发中,尚未发布.
所以,在APOM文件中,我有以下部分:
<dependency>
<groupId>com.example</groupId>
<artifactId>project-b</artifactId>
<version>1.0.0-SNAPSHOT</version>
<\dependency>
Run Code Online (Sandbox Code Playgroud)
在工作中,我们有一个远程仓库(Nexus)和一个CI盒(运行Jenkins).
当我的同事改变B并提交给SVN时,Jenkins会选择更改,编译并将其放入远程仓库.大约在那个时候,我可能会B在本地打开,进行更改,编译并将其安装到我的本地仓库中.
B当我尝试mvn clean install A本地时,Maven现在如何解决?
前几天我们弄得一团糟,基本上不得不手动删除本地存储库,以确保我们得到了我们期望获得的版本.所以我现在想弄清楚究竟发生了什么.(因此,如果你有详细文档中的地点的链接,那也将非常感激...)在本地,我有时在我的存储库文件夹中有一些SNAPSHOT版本,一个没有,有几个用什么看起来像SNAPSHOT文件名部分之后的时间戳...
snapshot dependency-management pom.xml maven dependency-resolver
我是ASP.NET MVC 4的新手.我在ASP.NET MVC 4项目中使用了自定义依赖项解析器,以便使用依赖注入框架.
依赖解析器在ASP.NET MVC 4中的作用是什么?
简短问题:与此未解决的问题相同
长问题:
我刚刚从MVC 4 + Web Api解决方案中移植了一些代码,该解决方案使用Autofac进入我的新解决方案,该解决方案也使用Autofac但仅使用Web Api 2(没有MVC 5.1项目,只有web api).
在我之前的解决方案中,我有MVC4和Web Api所以我有2个Bootstrapper.cs文件,每个文件一个.我复制了新项目的Web Api引导程序.
现在我在新解决方案中有两个需要依赖的项目.让我们假设我必须使用DependencyResolver.Current.GetService<T>()尽管它是一个反模式.
起初,直到我将MVC依赖关系解析器设置为同一个容器,这才起作用:
GlobalConfiguration.Configuration.DependencyResolver =
new AutofacWebApiDependencyResolver(container);
//I had to pull in Autofac.Mvc and Mvc 5.1 integration but this line fixed it
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
Run Code Online (Sandbox Code Playgroud)
奇怪的是,这样做只能在其中一个项目中修复它!情况如下:
Solution.Web project
Bootstrapper.cs that registers both dependency resolvers for web api and mvc.
Solution.ClassLib project
var userRepo = DependencyResolver.Current.GetService<IUserRepo>(); //Good! :)
Solution.WindowsWorkflow project
var userRepo = DependencyResolver.Current.GetService<IUserRepo>(); //Throws exception :(
Run Code Online (Sandbox Code Playgroud)
例外情况是:无法创建请求生存期范围,因为HttpContext不可用.
现在,在我们开始指责工作流程之前,只知道我已经在另一个解决方案中使用了这个确切的设置,工作流程能够正常使用DependencyResolver.所以我怀疑这与使用更新版本的Autofac以及工作流异步运行的事实有关(就像我关于异步代码链接的问题一样)
我尝试使用切换所有注册代码InstancePerLifetimeScope()而不是InstancePerHttpRequest()尝试创建范围:
using (var …Run Code Online (Sandbox Code Playgroud) 考虑类的ConfigureServices方法中的以下代码Startup-
services.AddTransient<IAuthorizationHandler, BlockUsersHandler>();
services.AddTransient<IAuthorizationHandler, BlockClaimHandler>();
services.AddAuthorization(option =>
{
option.AddPolicy("NotHacker", policy =>
{
policy.AddRequirements(new BlockUsersRequirement("Hacker"));
});
option.AddPolicy("NotThatClaim", policy =>
{
policy.AddRequirements(new BlockClaimRequirement(new Claim("ThatClaimType", "ThatClaim")));
});
});
Run Code Online (Sandbox Code Playgroud)
这些是自定义类实现 -
public class BlockUsersRequirement : IAuthorizationRequirement
{
// Code goes here
}
public class BlockUsersHandler : AuthorizationHandler<BlockUsersRequirement>
{
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, BlockUsersRequirement requirement)
{
// Code goes here
}
}
public class BlockClaimRequirement : IAuthorizationRequirement
{
// Code goes here
}
public class BlockClaimHandler : AuthorizationHandler<BlockClaimRequirement>
{
protected …Run Code Online (Sandbox Code Playgroud) 我已创建和MVC 4 Web应用程序,并决定在此应用程序中使用web api.我正在为MVC Web应用程序使用ninject依赖解析器.现在我想对web api使用这个ninject依赖解析器.但是这里提出的问题mvc IDependencyResolver命名空间是:using System.Web.Mvc
和web api IDependencyResolver是using System.Web.Http.Dependencies
那我怎么解决这个问题呢?
最后我想要这样的东西:
// Use the container and the NinjectDependencyResolver as
// application's resolver
var resolver = new NinjectDependencyResolver(container);
//Register Resolver for MVC
DependencyResolver.SetResolver(resolver);
//Register Resolver for Web Api
GlobalConfiguration.Configuration.DependencyResolver = resolver;
Run Code Online (Sandbox Code Playgroud) 我正在研究用TypeScript 2编写的角度2项目,我目前面临着导入机制的问题.
我项目的每个子文件夹里面都有一个"index.ts"文件,即导出所述文件夹包含的类.
所以,在我的"app"目录中,我有
然后,index.ts文件包含:
export * from './app.component';
export * from './app.module';
export * from './app.routes';
Run Code Online (Sandbox Code Playgroud)
我的问题是我无法从位于同一目录中的文件导入导出的类.
例如,在我的app.module.ts中,我想导入应用程序组件.如果我做 :
import { AppComponent } from './app.component';
Run Code Online (Sandbox Code Playgroud)
一切正常!编译时和运行时没有错误.生活很酷,生活很美好.
但我不能做到以下几点:
import { AppComponent } from '.'; // or './', or even './index'
Run Code Online (Sandbox Code Playgroud)
IDE(Visual Studio)实际上正确解析了导入(它编译时没有错误).我甚至从Intellisence获得自动完成功能......
但是我在运行时遇到这个错误:
Error: Unexpected value 'undefined' imported by the module 'AppModule'
Run Code Online (Sandbox Code Playgroud)
我只是不知道为什么.
注意:通过从子文件夹中的index.ts导入我没有任何错误(例如,我可以从也有索引的'./core'导入).
先感谢您 :)
假设我在容器中注册了多个对象,都实现了相同的接口:
container.Register(
Component.For<ITask>().ImplementedBy<Task1>(),
Component.For<ITask>().ImplementedBy<Task2>(),
Component.For<ITask>().ImplementedBy<Task3>(),
Component.For<ITask>().ImplementedBy<Task4>(),
);
Run Code Online (Sandbox Code Playgroud)
我希望解决ITask的所有实现:
var tasks = container.ResolveAll<ITask>();
Run Code Online (Sandbox Code Playgroud)
有没有办法控制已解析实例的顺序?
注意:显然,我可以在ITask上实现一个Order或Priority属性,只是对任务列表进行排序,但我正在寻找一个更低级别的解决方案.
我正在使用简单的注入器,但IDependencyResolver在 .net core 2 中找不到,使用IServiceProvider而不是使用是正确的选择IDependencyResolver,因为没有“ IDependencyScope BeginScope()” IserviceProvider,我有点困惑是否使用IServiceProvider。我读了 .net core 2.0有更好的内置 DI 支持,但不确定如何利用它。
public class SimpleInjectorWebApiDependencyResolver : IDependencyResolver
{
private readonly Container container;
public SimpleInjectorWebApiDependencyResolver(Container container)
{
this.container = container;
}
[DebuggerStepThrough]
public IDependencyScope BeginScope() // what should i use instead of IdependencyScope in .Net Core
{
return this;
}
[DebuggerStepThrough]
public object GetService(Type serviceType)
{
return ((IServiceProvider)this.container).GetService(serviceType);
}
[DebuggerStepThrough]
public IEnumerable<object> GetServices(Type serviceType)
{
//return this.container.GetAllInstances(serviceType);
IServiceProvider provider = …Run Code Online (Sandbox Code Playgroud) c# dependency-injection simple-injector dependency-resolver asp.net-core-2.0
在文档中明确指出您需要为所有平台实现:
您必须在每个平台项目中提供一个实现。如果没有注册接口实现,则将
DependencyService无法Get<T>()在运行时解析该方法。
我没有提供实现,所以应用程序崩溃了。但是如果我不需要该平台的实现,我该怎么办?提供这样的无体方法?
public void HideKeyboard()
{
// We need an implementation for the DependencyService, even it is empty.
}
Run Code Online (Sandbox Code Playgroud)
我应该提供一个实现吗?
public void HideKeyboard()
{
try
{
InputPane myInputPane = InputPane.GetForCurrentView();
myInputPane.TryHide();
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}
}
Run Code Online (Sandbox Code Playgroud)
还是DependencyService这里使用了错误的选项?
c# ×4
angular ×2
.net ×1
asp.net-core ×1
asp.net-mvc ×1
autofac ×1
import ×1
maven ×1
ninject ×1
observable ×1
pom.xml ×1
promise ×1
snapshot ×1
typescript ×1
xamarin ×1