小编Tan*_*uyB的帖子

Docker ip for windows

我正在使用基本的.NET核心项目测试Docker.我从这个docker文件构建和映像:

FROM microsoft/dotnet:latest

COPY . /app

WORKDIR /app/API

RUN ["dotnet", "restore"]

RUN ["dotnet", "build"]

EXPOSE 5000/tcp

CMD ["dotnet", "run", "--server.urls", "http://*:5000"]
Run Code Online (Sandbox Code Playgroud)

我跑了它,它完美无瑕.现在唯一的问题是,它运行的是什么IP?

我在Windows上运行Docker!

问候

windows docker asp.net-core

9
推荐指数
2
解决办法
1万
查看次数

Angular2:当路径参数改变时调用方法/ ngoninit

现在我正在制作一种网上商店,在我的主页上我有一个类别的下拉列表示父母猫A和子猫B和C.

Cat A,B和C均由1组分CatAComponent表示.当我第一次进入其中一只猫时,我的ngoninit被调用,页面显示它需要显示的内容.

当我想点击另一个子猫时,我仍然在同一个组件上,但只有一个路径的参数更改(例如我在本地主机:123/CatA/CatB,现在我在本地主机:123/CatA/CatC,只更改了一个参数,因此不会调用ngOnInit,也不会调用我的更新方法).

有什么方法可以绕过这个吗?我不能在我的视图文件中放置(单击)方法来引用该方法,类别的菜单在另一个viewcomponent中.

只有参数更改后才可以调用NgOnInit吗?

typescript ngoninit angular

6
推荐指数
1
解决办法
6244
查看次数

.NET Core 2.0分离Startup.cs服务注入

所以现在我得到了一个使用N层架构的项目(3层:API,BL,DAL).我担心的是我的所有服务注入都发生在我的Startup.cs文件中.

是否有可能将它们转移到正确的解决方案?

EG Startup.cs ConfigureServices方法

public void ConfigureServices(IServiceCollection services)
    {
        //MVC
        services.AddMvc();

        //Swagger
        services.AddSwaggerGen(c =>
        {
            c.SwaggerDoc("v1", new Info
            {
                Title = "2Commit Blogpost API",
                Version = "v1"
            });
        });
        services.ConfigureSwaggerGen(options =>
        {
            options.CustomSchemaIds(x => x.FullName);
        });

        //Mediatr
        services.AddScoped<IMediator, Mediator>();
        services.AddTransient<SingleInstanceFactory>(sp => sp.GetService);
        services.AddTransient<MultiInstanceFactory>(sp => sp.GetServices);
        services.AddMediatorHandlers(typeof(Startup).Assembly);

        //MongoDB
        services.Configure<MongoSettings>(s =>
        {
            s.Database = Configuration.GetSection("MongoConnection:Database").Value;
        });
        services.AddSingleton<IMongoClient, MongoClient>(client => new MongoClient(Configuration.GetSection("MongoConnection:ConnectionString").Value));

        //BL
        services.AddTransient<IUserService, UserService>();
        services.AddTransient<IAccountService, AccountService>();

        //DAL
        services.AddTransient<IRepository, MongoRepository>();

        //Authentication
        services.AddAuthentication()
            .AddJwtBearer(jwt =>
            {
                var signingKey =
                    new SymmetricSecurityKey(Encoding.ASCII.GetBytes(Configuration.GetSection("Secret:Key").Value));

                jwt.TokenValidationParameters = …
Run Code Online (Sandbox Code Playgroud)

c# .net-core asp.net-core

6
推荐指数
1
解决办法
1347
查看次数

如何处理构建“dist”文件夹

所以我完成了一个非常小的 angular2 项目,并使用命令“ng build --prod”通过 angular-cli 构建它。

我从中得到一个“dist”文件夹。但是我应该如何处理这个 dist 文件夹才能使其运行?将其发布到服务器?

问候。

publish build angular-cli angular

5
推荐指数
1
解决办法
1万
查看次数

RXJS - 对属性数组的多个可观察调用

我对 rxjs 不太熟悉,而且我有一个相当简单的案例,我无法在 angular 中解决。

我有一个 http 调用来检索一个组,该组包含一个“好友 ID”列表、一个“流派 ID”列表和一个“区域 ID”。

要通过“好友 id”获取好友对象,我必须通过我的服务调用 API(返回 1 个给定 id 的好友)。

为了获取我的流派对象,我可以从我的商店中检索它们,对于地区也是如此。

问题是我无法用管道找到解决方案。

this.buddyService.getGroup(groupId).pipe(
    mergeMap((group) => forkJoin(
          mergeMap(() => forkJoin(group.buddyIds.map((id) => this.buddyService.getBuddy(id)))), 
          mergeMap(() => forkJoin(group.genreIds.map((id) => this.store.select(GenreState.genre(id))))),
          switchMap(() => this.store.select(RegionState.region(group.regionId))))
    ), takeUntil(this.destroyed$)
).subscribe(([group, buddies, genres, region]) => {

});
Run Code Online (Sandbox Code Playgroud)

所以第一个 mergeMap 将在 1 次订阅中获得所有结果,然后我有 3 个子调用来获取好友、流派和地区。

我想要我的初始响应(组)和 1 个订阅中的 3 个子调用的结果,显然这个解决方案不起作用,我似乎无法得到其他东西。

任何帮助将不胜感激,谢谢!

observable rxjs typescript angular

5
推荐指数
2
解决办法
4021
查看次数

具有自定义端点名称的WEB API .NET Action

因此,我已经在.NET中设置了一个后端,并且基本的HTTP调用正在工作。现在,我需要一个替代方法,该方法将不按ID搜索而是按属性搜索,因此我想在结尾处进行具有其他属性的REST调用。

这是我的控制器的2种方法:

public IHttpActionResult GetCategory(int id)
{
    var category = _productService.GetCategoryById(id);

    if (category == null) return NotFound();
    var dto = CategoryToDto(category);
    return Ok(dto);
}


public IHttpActionResult GetCategoryByName(string name)
{
    var category = _productService.GetCategoryByName(name);

    if(category == null) return NotFound();
    var dto = CategoryToDto(category);
    return Ok(dto);
}
Run Code Online (Sandbox Code Playgroud)

我的API配置配置如下:/api/{controller}/{action}/{id}

因此,第一个呼叫可与此呼叫一起使用: /api/category/getcategory/2

当我通过此调用尝试第二种方法时: /api/category/getcategorybyname/Jewelry

我收到一条错误消息,说控制器中没有任何动作与请求匹配。

这是什么问题

c# asp.net entity-framework asp.net-web-api

4
推荐指数
1
解决办法
3233
查看次数

.NET核心API网关

我在微服务学校附近有一些工作要做.

我有建筑概念,但需要一个实现炫耀.我将使用angular2作为客户端,希望使用.NET核心API网关将我的请求分派给不同的服务.

对此最好的方法是什么?我对使用Rx.Net有所了解,但没有我可以遵循的确定示例或实现.

那么我该怎么做才能在.NET Core中实现API网关呢?

c# api gateway microservices .net-core

4
推荐指数
1
解决办法
7935
查看次数

使用 RabbitMQ 进行不同 Docker 容器之间的通信

我想在存储在不同 Docker 容器中的 2 个应用程序之间进行通信,这两个应用程序都属于同一 Docker 网络。我将为此使用消息队列(RabbitMQ)

我是否应该创建第 3 个 Docker 容器作为我的 RabbitMQ 服务器运行,然后为这 2 个特定容器创建一个通道?这样,如果我需要例如需要与其他 2 个通信的第三个应用程序,我可以创建更多频道?

问候!

message-queue rabbitmq docker microservices

4
推荐指数
1
解决办法
1345
查看次数

.NET Core 2.0 BasePath错误

刚刚开始使用新的.NET Core 2.0应用程序,但获得奇怪的突然行为,似乎找不到任何东西.

点击.Run()我的时弹出以下错误BuildWebHost().:

System.InvalidOperationException: A path base can only be configured using IApplicationBuilder.UsePathBase().
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.<BindAddressAsync>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.AddressesStrategy.<BindAsync>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.<BindAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.<StartAsync>d__21`1.MoveNext() …
Run Code Online (Sandbox Code Playgroud)

c# .net-core asp.net-core

4
推荐指数
2
解决办法
7176
查看次数

ASP.NET Core默认路由无效

似乎无法让我的默认路由在ASP.NET Core 2.0中运行,我忽略了什么?

Startup.cs

public class Startup
{
    public IConfiguration Configuration { get; set; }

    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc();
    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        app.UseMvc(routes => 
        {
            routes.MapRoute("default", "{controller}/{action}/{id?}", new { controller = "Home", action = "Index" });
        });
    }
}
Run Code Online (Sandbox Code Playgroud)

HomeController.cs

[Route("[controller]")]
public class HomeController : Controller
{
    public IActionResult Index()
    {
        return View();
    }
}
Run Code Online (Sandbox Code Playgroud)

当我浏览网址时,没有任何反应,没有重定向到主页?

c# asp.net-core-mvc asp.net-core

4
推荐指数
1
解决办法
3115
查看次数

.NET Core 对象 JSON 序列化为 Javascript 格式

我在将 C# 对象序列化为纯 JSON 字符串时遇到了一些问题。

我使用 JsonConvert(Newtonsoft 的)将模型格式化为 JSON。问题是在某些 Javascript 中使用了 JSON 字符串 get,但格式并不好,因为在引号中被写为 ""e;" 而不是 "'"。关于如何解决这个问题有任何想法吗?

//...
@{
    var dataJson = JsonConvert.SerializeObject(Model);
}
//...

<script>
    function ChangeGroup(type) {
        $.ajax({
            url: //...,
            data: @dataJson
        });
    }
</script>
Run Code Online (Sandbox Code Playgroud)

我得到的是这样的:

错误

我忘记设置一些格式选项?

javascript c# json json.net asp.net-core

4
推荐指数
1
解决办法
6164
查看次数

C# LINQ 过滤器深层嵌套列表

我有一个基于包含其他列表的列表的结构。我需要根据列表最深部分的属性值来过滤列表。

现在我正在这样做:

queryable = queryable
    .Include(x => x.Carriers)
    .ThenInclude(c => c.CarrierActions)
    .ThenInclude(ca => ca.Action)
    .ThenInclude(ac => ac.ActionFacts);

queryable = queryable
    .Where(x => x.Carriers.Any(
        carriers => carriers.CarrierActions.Any(
            carrieractions =>
                carrieractions.Action.ActionTypeId ==
                ActionTypeEnum.DosemeterCalculateDeepDose)));
Run Code Online (Sandbox Code Playgroud)

我加入所需的表,然后根据顶部列表下方 3 个级别的 ActionTypeId 来过滤它们。

首先,是否可以一步完成此操作(包括使用连接进行过滤),其次,第二部分不起作用,因为我的列表变空,但我确信该类型的操作会获取值。

顺便说一句,使用 .NET Core 2.0.3!

.net c# linq .net-core

1
推荐指数
1
解决办法
2391
查看次数