我Initialize对构造函数中通常使用的方法有点困惑.
为什么我不能把所有内容放在构造函数中,为什么下面的示例调用initialize方法?
private IAzureTable<Product> _productRepository;
public ProductService(string dataSourceID)
{
Initialize(dataSourceID);
}
private void Initialize(string dataSourceID)
{
this._productRepository = StorageHelper.GetTable<Product>(dataSourceID);
}
Run Code Online (Sandbox Code Playgroud)
是否有通常使用的约定?
在这个例子中,我需要这个词this的Initialize方法是什么?
我有自己的存储库,如下所示.但是,这并未考虑一些新功能,例如范围功能.有没有人有一个包含所有内容的存储库.我在网上搜索过这个,但是我找不到最新的东西.这就是我所拥有的.我希望有更多的东西,并提供许多方法的IQueryable:
namespace Services.Repositories
{
/// <summary>
/// The EF-dependent, generic repository for data access
/// </summary>
/// <typeparam name="T">Type of entity for this Repository.</typeparam>
public class GenericRepository<T> : IRepository<T> where T : class
{
public GenericRepository(DbContext dbContext)
{
if (dbContext == null)
throw new ArgumentNullException("An instance of DbContext is required to use this repository", "context");
DbContext = dbContext;
DbSet = DbContext.Set<T>();
}
protected DbContext DbContext { get; set; }
protected DbSet<T> DbSet { get; set; }
public virtual IQueryable<T> Find(Expression<Func<T, …Run Code Online (Sandbox Code Playgroud) 我有我在我的应用程序中使用的代码:
private async Task configSendGridasync(IdentityMessage message)
{
var myMessage = new SendGridMessage();
myMessage.AddTo(message.Destination);
myMessage.From = new System.Net.Mail.MailAddress(
"a@b.com", "AB Registration");
myMessage.Subject = message.Subject;
myMessage.Text = message.Body;
myMessage.Html = message.Body;
var credentials = new NetworkCredential(
ConfigurationManager.AppSettings["mailAccount"],
ConfigurationManager.AppSettings["mailPassword"]
);
// Create a Web transport for sending email.
var transportWeb = new Web(credentials);
// Send the email.
if (transportWeb != null)
{
await transportWeb.DeliverAsync(myMessage);
}
else
{
Trace.TraceError("Failed to create Web transport.");
await Task.FromResult(0);
}
}
Run Code Online (Sandbox Code Playgroud)
它在这里被称为:
public async Task<IHttpActionResult> Register(RegisterBindingModel model)
{ …Run Code Online (Sandbox Code Playgroud) 更新: 提醒一下,如果有人可以告诉我如何在不使用手势的情况下实现此功能,那么就有500点奖金>
我正在使用ViewCell和手势识别器打开一个带有以下代码的选择器.ViewCell左侧有一个标签,右侧有一个标签区域,最初在应用程序启动时填充,稍后在单击ViewCell时使用选择器填充.
XAML
<ViewCell x:Name="ati" Tapped="OpenPickerCommand">
<Grid VerticalOptions="CenterAndExpand" Padding="20, 0">
<Grid.GestureRecognizers>
<TapGestureRecognizer
Command="{Binding OpenPickerCommand}"
CommandParameter="{x:Reference atiPicker}" NumberOfTapsRequired="1" />
</Grid.GestureRecognizers>
<local:LabelBodyRendererClass Text="Answer Time Interval" HorizontalOptions="StartAndExpand" />
<Picker x:Name="atiPicker" IsVisible="false" HorizontalOptions="End" SelectedIndexChanged="atiPickerSelectedIndexChanged" ItemsSource="{Binding Times}"></Picker>
<local:LabelBodyRendererClass x:Name="atiLabel" HorizontalOptions="End"/>
</Grid>
</ViewCell>
<ViewCell x:Name="pti" Tapped="OpenPickerCommand">
<Grid VerticalOptions="CenterAndExpand" Padding="20, 0">
<Grid.GestureRecognizers>
<TapGestureRecognizer
Command="{Binding OpenPickerCommand}"
CommandParameter="{x:Reference ptiPicker}" NumberOfTapsRequired="1" />
</Grid.GestureRecognizers>
<local:LabelBodyRendererClass Text="Phrase Time Interval" HorizontalOptions="StartAndExpand" />
<Picker x:Name="ptiPicker" IsVisible="false" HorizontalOptions="End" SelectedIndexChanged="ptiPickerSelectedIndexChanged" ItemsSource="{Binding Times}"></Picker>
<local:LabelBodyRendererClass x:Name="ptiLabel" HorizontalOptions="End"/>
</Grid>
</ViewCell>
Run Code Online (Sandbox Code Playgroud)
C#这适用于使用CommandParameter的不同选择器(ati,bti,pti等)
public SettingsPage()
{
InitializeComponent();
BindingContext = …Run Code Online (Sandbox Code Playgroud) 我的应用程序使用的是SQL Server 2012,EF6,MVC和Web API.
它还使用存储库和各种文件,例如:
DatabaseFactory.cs
Disposable.cs
IDatabaseFactory.cs
IRepository.cs
IUnitOfWork.cs
RepositoryBase.cs
UnitOfWork.cs
Run Code Online (Sandbox Code Playgroud)
我们已经在控制器和存储库之间使用服务层来处理一些复杂的业务逻辑.我们没有计划改变到不同的数据库,并且已经向我指出最近的想法是EF6是一个存储库,所以为什么要在它之上构建另一个存储库以及为什么我拥有上面的所有文件.
我开始认为这是一种明智的做法.
有没有人知道那些实现EF6而没有存储库的服务层的例子.我在网上的搜索揭示了许多复杂的代码示例,这些示例在任何情况下都显得过于复杂.
我的问题也是在使用服务层时,我在哪里放:
context = new EFDbContext()
Run Code Online (Sandbox Code Playgroud)
在控制器,服务层或两者?我读到我可以通过依赖注入来做到这一点.我已经将Unity用作IOC,但我不知道如何做到这一点.
我有一个C#代码,如下所示:
foreach (var entry in this.ChangeTracker.Entries()
.Where(e => e.Entity is IAuditableTable &&
e.State == EntityState.Added))
{
IAuditableTable e = (IAuditableTable)entry.Entity;
e.ModifiedDate = DateTime.Now;
}
Run Code Online (Sandbox Code Playgroud)
这似乎就像foreach和LINQ的结合.sometone告诉我,我可以删除foreach并将其合并到一个LINQ语句中
我的$ http调用看起来像这样,我想知道最灵活的方法来处理.success和.error中返回的所有参数?
this.$http({ url: "/api/x, method: "GET" })
.success((??) : void => {
})
.error((??) : void => {
})
Run Code Online (Sandbox Code Playgroud)
Angular文档告诉我返回以下内容:
data – {string|Object} – The response body transformed with the transform functions.
status – {number} – HTTP status code of the response.
headers – {function([headerName])} – Header getter function.
config – {Object} – The configuration object that was used to generate the request.
statusText – {string} – HTTP status text of the response.
Run Code Online (Sandbox Code Playgroud)
angular.d.ts告诉我:
interface IHttpPromiseCallback<T> {
(data: T, …Run Code Online (Sandbox Code Playgroud) 我已经在我的应用程序中更新,修改和删除了文件,现在我已准备好提交.这是状态:
C:\G\ab\WebAdminApp>git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: WebAdminApp.csproj
modified: WebAdminApp.csproj.user
modified: app/admin/controllers/ContentController.ts
deleted: app/admin/interfaces/IEnumService.ts
modified: app/admin/interfaces/IHomeController.d.ts
modified: lib/pagedown/Markdown.Sanitizer.ts
deleted: lib/typings/global.ts
modified: package.json
modified: ../abilitest-admin.v12.suo
Untracked files:
(use "git add <file>..." to include in what will be committed)
app/interfaces/IEnumService.d.ts
app/interfaces/IUtilityService.d.ts
../npm-debug.log
Run Code Online (Sandbox Code Playgroud)
没有更改添加到提交(使用"git add"和/或"git commit -a")
当我进入:
git add . …Run Code Online (Sandbox Code Playgroud) 我有一个AngularJS WebAPI应用程序.
据我所知,OPTIONS请求是由浏览器自动构建的.
POST http://localhost:3048/Token HTTP/1.1
Host: localhost:3048
Connection: keep-alive
Content-Length: 78
Accept: application/json, text/plain, */*
Origin: http://localhost:2757
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36
Content-Type: application/x-www-form-urlencoded
Referer: http://localhost:2757/Auth/login
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.8
grant_type=password&username=xxx%40live.com&password=xxx
Run Code Online (Sandbox Code Playgroud)
响应:
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Length: 971
Content-Type: application/json;charset=UTF-8
Expires: -1
Server: Microsoft-IIS/8.0
Access-Control-Allow-Origin: *
Set-Cookie: .AspNet.Cookies=CpvxrR1gPFNs0vP8GAmcUt0EiKuEzLS1stLl-70O93wsipJkLUZuNdwC8tZc5M0o1ifoCjvnRXKjEBk3nLRbFlbldJLydW2BWonr5JmBjRjXZyKtcc29ggAVhZlc2E-3gGDlyoZLAa5Et8zrAokl8vsSoXmHnsjrxZw0VecB_Ry98Ln84UuKdeHlwSBnfaKKJfsN-u3Rsm6MoEfBO5aAFEekhVBWytrYDx5ks-iVok3TjJgaPc5ex53kp7qrtH3izbjT7HtnrsYYtcfPtmsxbCXBkX4ssCBthIl-NsN2wObyoEqHMpFEf1E9sB86PJhTCySEJoeUJ5u3juTnPlQnHsk1UTcO0tDb39g-_BD-I4FWS5GMwxLNtmut3Ynjir0GndwqsvpEsLls1Y4Pq7UuVCTn7DMO4seb64Sy8oEYkKZYk9tU4tsJuGD2CAIhdSc-lAmTAA78J5NOx23klkiuSe_SSiiZo5uRpas_1CFHjhi1c8ItEMpgeTsvgTkxafq5EOIWKPRxEHbCE8Dv106k5GlKK5BaH6z7ESg5BHPBvY8; path=/; HttpOnly
X-SourceFiles: =?UTF-8?B?QzpcR1xhYmlsaXRlc3Qtc2VydmVyXFdlYlJvbGVcVG9rZW4=?=
X-Powered-By: ASP.NET
Date: Tue, 13 Jan 2015 04:54:55 GMT
{"access_token":"TkJ2trqT ....
Run Code Online (Sandbox Code Playgroud)
现在登录
我注销哪个只是删除令牌并再次登录.发生了不同的事情.在它没有发送OPTIONS之前,但现在确实如此.以前的请求/响应是否会导致浏览器在第二次登录时影响不同?
OPTIONS http://localhost:3048/Token HTTP/1.1 …Run Code Online (Sandbox Code Playgroud) 我有一个AngularJS SPA应用程序,我使用Visual Studio 2015开发.当我点击发布它发布index.html并且工作得很好.但是,如果我在页面上并单击刷新,则会尝试刷新SPA页面,例如example.com/home/about.这失败了,因为我没有家/关于页面.
有没有办法可以修改我的web.config文件(仅用于本地测试),这样它实际上会转到index.html(加载它)然后转到/ home/about状态?
这是我当前的web.config:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
</configuration>
Run Code Online (Sandbox Code Playgroud) angularjs ×2
asp.net ×2
asp.net-mvc ×2
c# ×2
constructor ×1
cors ×1
email ×1
git ×1
github ×1
http ×1
http-headers ×1
linq ×1
sendgrid ×1
typescript ×1
xamarin ×1