在性能方面,会这2种方法运行GetAllWidgets()和GetAllFoos()并行?
有没有理由使用一个而不是另一个?在编译器的幕后似乎发生了很多事情,所以我觉得不清楚.
=============方法A:使用多个等待======================
public async Task<IHttpActionResult> MethodA()
{
var customer = new Customer();
customer.Widgets = await _widgetService.GetAllWidgets();
customer.Foos = await _fooService.GetAllFoos();
return Ok(customer);
}
Run Code Online (Sandbox Code Playgroud)
===============方法B:使用Task.WaitAll =====================
public async Task<IHttpActionResult> MethodB()
{
var customer = new Customer();
var getAllWidgetsTask = _widgetService.GetAllWidgets();
var getAllFoosTask = _fooService.GetAllFos();
Task.WaitAll(new List[] {getAllWidgetsTask, getAllFoosTask});
customer.Widgets = getAllWidgetsTask.Result;
customer.Foos = getAllFoosTask.Result;
return Ok(customer);
}
Run Code Online (Sandbox Code Playgroud)
=====================================
我对使用angularfire2的angular(v2.4)应用程序在开发环境(快速服务器)中运行顺畅.当我使用"npm run build"构建它时,Webpack2构建应用程序并将其放入名为"target"的文件夹中.当我使用"npm run server"从目标文件夹运行构建的应用程序时,服务器启动并且浏览器不会显示应用程序的标题.在浏览器的控制台中,我收到此错误:
"未处理的承诺拒绝:模板解析错误:'app'不是已知元素:如果'app'是Angular组件,则验证它是该模块的一部分.如果'app'是Web组件,则添加"CUSTOM_ELEMENTS_SCHEMA"到这个组件的'@ NgModule.schemas'来抑制这个消息."
我在这里为您提供应用程序的应用程序组件index.ts,main.ts.万一,如果你想看到webpack.config.js,我也可以提供.
这是我的应用程序组件:
import { Component } from '@angular/core';
import { AuthService } from '../../auth';
@Component({
selector: 'app',
template: `
<app-header
[authenticated]="auth.authenticated"
(signOut)="signOut()"></app-header>
<router-outlet></router-outlet>
<app-footer
[authenticated]="auth.authenticated"></app-footer>
`
})
export class AppComponent {
constructor(private auth: AuthService) {}
signOut(): void {
this.auth.signOut();
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的app模块的index.ts:
import {NgModule} from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouterModule} from '@angular/router';
import { HttpModule } from '@angular/http';
import { AuthModule } from '../auth';
import { FirebaseModule } …Run Code Online (Sandbox Code Playgroud) 我正在再次尝试将参数传递给我的应用程序.从RC5开始,我必须使用ngModule.(此解决方案:自从RC5以来,将asp.net服务器参数传递给Angular 2应用程序不再有效)
如何将参数传递给ngModule?
index.html的:
<script>
System.import('app').then(module => module.main('This is RIGHT'),
console.error.bind(console)
);
</script>
Run Code Online (Sandbox Code Playgroud)
main.ts:
import { browserDynamicPlatform } from '@angular/platform-browser-dynamic';
import { provide } from '@angular/core';
import { AppModule } from './app.module';
export function main(test: string) {
browserDynamicPlatform().bootstrapModule(AppModule, [{ providers: provide('Test', { useValue: test, }) }]);
}
Run Code Online (Sandbox Code Playgroud)
app.module.ts
import { NgModule, provide } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
@NgModule({
imports: [
BrowserModule
],
declarations: [ …Run Code Online (Sandbox Code Playgroud) 我有一个与实体框架映射的LINQ查询,看起来像这样:
image = this.Context.ImageSet
.Where(n => n.ImageId == imageId)
.Where(n => n.Albums.IsPublic == true)
.Single();
Run Code Online (Sandbox Code Playgroud)
这将返回单个图像对象并按预期工作.
但是,此查询将返回数据库中我的Image表的所有属性.在正常情况下,这样会很好,但这些图像包含很多二进制数据需要很长时间才能返回.
基本上,在它的当前状态我的linq查询正在做:
Select ImageId, Name, Data
From Images
...
Run Code Online (Sandbox Code Playgroud)
但我需要一个执行此instread的查询:
Select ImageId, Name
From Images
...
Run Code Online (Sandbox Code Playgroud)
注意我想加载除数据之外的所有内容.(我可以在第二次异步传递中获取此数据)
MVVM的新手,请原谅我的无知.
我认为我正确使用它,但我发现我的ViewModel有太多这些:
RaisePropertyChanged("SomeProperty")
Run Code Online (Sandbox Code Playgroud)
每次我设置一个房产,我都要提高那个该死的房产.
我想念我可以去的日子:
public int SomeInteger { get; private set;}
Run Code Online (Sandbox Code Playgroud)
这些天我必须在任何地方坚持"RaisePropertyChanged"或我的UI不反映变化:(
我做错了还是其他人对过多的魔法字符串和旧学校的业主制定者感到恼火?
我应该使用依赖属性吗?(我怀疑这会对代码膨胀有帮助)
尽管存在这些问题,我仍然认为MVVM是要走的路,所以我想这就是问题.
当一切都在HTTPS(身份验证,Web服务等)时,我有一个非常好的站点.如果我混合使用http和https,则需要更多编码(跨域问题).
我似乎没有看到很多完全使用HTTPS的网站,所以我想知道这样做是不是一个坏主意?
编辑:网站将托管在Azure云上,其中带宽和CPU使用率可能是个问题...
================================================== ==============
编辑:解决方案升级到2.0 Final后 - 在RC5升级后将服务器参数传递给ngModule
================================================== ================
有没有将服务器参数传递给Angular 2应用程序的方法?
即我想使用MVC对象"HttpContext.User.Identity.Name",并在我的角度2应用程序中的任何地方注入它.
在角度1中,这可以使用ng".constant"并将.Net对象序列化为index.cshtml中的JSON.
看起来有一种方法可以传递params,但这不适用于.Net代码. 在Angular 2中定义全局常量
//HTML - Bootstrapping
<script>
System.import('app/main').then(null, console.error.bind(console));
//I WOULD LIKE TO PASS SOME PARAMS TO APP/MAIN HERE
</script>
Run Code Online (Sandbox Code Playgroud)
最终解决方案:(非常感谢蒂埃里)
index.cshtml:
<script>
System.import('app/main').then(
module =>
module.main(
{
name: '@User.Identity.Name',
isAuthenticated: User.Identity.IsAuthenticated.ToString().ToLowerInvariant(),
}
),
console.error.bind(console)
);
</script>
Run Code Online (Sandbox Code Playgroud)
main.ts:
...
import {provide} from '@angular/core';
...
export function main(params) {
bootstrap(AppComponent,
[
provide('Name', { useValue: params.name }),
provide('IsAuthenticated', { useValue: params.isAuthenticated }),
ROUTER_PROVIDERS,
HTTP_PROVIDERS,
LoggerService,
AuthenticationService
]);
}
Run Code Online (Sandbox Code Playgroud)
用法:
import …Run Code Online (Sandbox Code Playgroud) 我想在Silverlight 3中删除新Popup控件的灰色标题.
任何想法,如果这是可能的?
我有一个支持本地化的网站。我希望能够在英语和法语之间切换。
假设用户当前位于URL:http : //www.mysite.com/ zh_ / Home
我想重定向到:http : //www.mysite.com/ fr / Home
如果用户单击“法语”链接,如何将URL部分更改为“ fr”,但不更改URL的“家庭”部分(基本上我想保留用户的当前位置)
希望我的问题有道理!我可能缺少一些非常基本的东西?
编辑:种找到解决方案。
<%= Html.ActionLink("Français", ViewContext.RouteData.Values["action"].ToString(), ViewContext.RouteData.Values["controller"].ToString(), new { culture = "fr" }, null)%>
<%= Html.ActionLink("English", ViewContext.RouteData.Values["action"].ToString(), ViewContext.RouteData.Values["controller"].ToString(), new { culture = "en" }, null)%>
Run Code Online (Sandbox Code Playgroud)
这将维护当前URL的操作/控制器。也许有一个更清洁的解决方案?
在Windows 8应用程序中使用Unity for IoC.
我想知道注册我的类型最好的地方在哪里?
我目前正在考虑在App.xaml.cs中执行此操作并覆盖OnLaunch事件.
出于某种原因,我的数据库没有被创建,我没有收到任何错误.我正在使用"SQL Server"
要在global.asax.ca文件中初始化数据库:
protected void Application_Start(object sender, EventArgs e)
{
//BREAKPOINT HITS. GOOD
Database.SetInitializer<MenuManagerContext>(new MenuManagerServiceInitializer());
}
Run Code Online (Sandbox Code Playgroud)
...
public class MenuManagerServiceInitializer : CreateDatabaseIfNotExists<MenuManagerContext>
{
//BREAKPOINT NEVER HITS. BAD
protected override void Seed(MenuManagerContext context)
{
context.Chains.Add(...);
context.SaveChanges();
base.Seed(context);
}
}
Run Code Online (Sandbox Code Playgroud)
有没有为什么没有创建数据库的想法?我甚至没有收到错误,所以很难说出错了什么......
angular ×3
asp.net-mvc ×2
silverlight ×2
.net ×1
async-await ×1
c# ×1
https ×1
iis ×1
iis-7 ×1
linq ×1
mvvm ×1
performance ×1
ssl ×1
webpack ×1
webpack-2 ×1
windows-8 ×1