小编rem*_*lam的帖子

如何在C#Core Console应用程序中使用MemoryCache?

我想使用Microsoft.Extensions.Caching.Memory.MemoryCache在.NET核2.0控制台应用程序(实际上,在其或者在控制台或在asp.net应用程序中使用的库)

我创建了一个测试应用程序:

using System;

namespace ConsoleTest
{
    class Program
    {
        static void Main(string[] args)
        {
            var cache = new Microsoft.Extensions.Caching.Memory.MemoryCache(new Microsoft.Extensions.Caching.Memory.MemoryCacheOptions());

            int count = cache.Count;
            cache.CreateEntry("item1").Value = 1;
            int count2 = cache.Count;
            cache.TryGetValue("item1", out object item1);
            int count3 = cache.Count;
            cache.TryGetValue("item2", out object item2);
            int count4 = cache.Count;

            Console.WriteLine("Hello World!");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

不幸的是,这不起作用.这些项目未添加到缓存中,无法检索它们.

我怀疑我需要使用DependencyInjection,做这样的事情:

using System;
using Microsoft.Extensions.DependencyInjection;

namespace ConsoleTest
{
    class Program
    {
        static void Main(string[] args)
        {
            var provider = new Microsoft.Extensions.DependencyInjection.ServiceCollection()
                .AddMemoryCache()
                .BuildServiceProvider();

            //And now?

            var …
Run Code Online (Sandbox Code Playgroud)

c# console-application .net-core

7
推荐指数
2
解决办法
7630
查看次数

C# Swashbuckle:过时的模型属性显示没有改变招摇

我在我的(输入)模型中将一个属性标记为过时

public class MyModel
{
   [Obsolete("Use 'OtherProperty'")]
   public string SomeProperty {get;set;}


   public List<string> OtherProperty {get;set;}
}
Run Code Online (Sandbox Code Playgroud)

但是,swagger 没有显示这两个属性之间的区别,也没有显示消息。

有什么方法可以让我大摇大摆地尊重 Obsolete 属性?或者我需要自己把它放在属性上方的 xml-comments 中吗?

c# swagger .net-core swashbuckle asp.net-core

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