InvalidOperationException:无法解析范围服务

2023-12-20

InvalidOperationException:无法从根提供程序解析范围服务“DrinkAndGo.Data.AppDbContext”。 DbInitializer.cs 中 DrinkAndGo.Data.DbInitializer.Seed(IApplicationBuilder applicationBuilder) +13 AppDbContext 上下文 = Startup.cs 中的 DrinkAndGo.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env) +46 DbInitializer.Seed(应用程序);

  using DrinkAndGo.Data.Models;
  using Microsoft.AspNetCore.Builder;
  using Microsoft.Extensions.DependencyInjection;
  using System.Collections.Generic;
  using System.Linq;

namespace DrinkAndGo.Data
{
public class DbInitializer
{

    public static void Seed(IApplicationBuilder applicationBuilder)
    {
        AppDbContext context =
            applicationBuilder.ApplicationServices.GetRequiredService<AppDbContext>();

        if (!context.Categories.Any())
        {
            context.Categories.AddRange(Categories.Select(c => c.Value));
        }

        if (!context.Drinks.Any())
        {
            context.AddRange
            (
                new Drink
                {
                    Name = "Beer",
                    Price = 7.95M,
                    ShortDescription = "The most widely consumed alcohol",
                    LongDescription = "Beer is the world's ",
                    Category = Categories["Alcoholic"],
                    ImageUrl = "http://imgh.us/beerL_2.jpg",
                    InStock = true,
                    IsPreferredDrink = true,
                    ImageThumbnailUrl = "http://imgh.us/beerS_1.jpeg"
                },
                new Drink
                {
                    Name = "Rum & Coke",
                    Price = 12.95M,
                    ShortDescription = "Cocktail made of cola, lime and rum.",
                    LongDescription = "The world's second most popular drink",
                    Category = Categories["Alcoholic"],
                    ImageUrl = "http://imgh.us/rumCokeL.jpg",
                    InStock = true,
                    IsPreferredDrink = false,
                    ImageThumbnailUrl = "http://imgh.us/rumAndCokeS.jpg"
                },
                new Drink
                {
                    Name = "Tequila ",
                    Price = 12.95M,
                    ShortDescription = "Beverage made from the blue agave plant.",
                    LongDescription = "Tequila (Spanish About this sound [teˈkila].",
                    Category = Categories["Alcoholic"],
                    ImageUrl = "http://imgh.us/tequilaL.jpg",
                    InStock = true,
                    IsPreferredDrink = false,
                    ImageThumbnailUrl = "http://imgh.us/tequilaS.jpg"
                },
                new Drink
                {
                    Name = "Wine ",
                    Price = 16.75M,
                    ShortDescription = "A very elegant alcoholic drink",
                    LongDescription = "Contrary to popular belief=.",
                    Category = Categories["Alcoholic"],
                    ImageUrl = "http://imgh.us/wineL.jpg",
                    InStock = true,
                    IsPreferredDrink = false,
                    ImageThumbnailUrl = "http://imgh.us/wineS.jpg"
                },
                new Drink
                {
                    Name = "Margarita",
                    Price = 17.95M,
                    ShortDescription = "A cocktail with sec, tequila and lime",
                    Category = Categories["Alcoholic"],
                    LongDescription = "Contrary to popular belief=",
                    ImageUrl = "http://imgh.us/margaritaL.jpg",
                    InStock = true,
                    IsPreferredDrink = false,
                    ImageThumbnailUrl = "http://imgh.us/margaritaS.jpg"
                },
                new Drink
                {
                    Name = "Whiskey with Ice",
                    Price = 15.95M,
                    ShortDescription = "The best way to taste whiskey",
                    LongDescription = "Contrary to popular belief,,
                    Category = Categories["Alcoholic"],
                    ImageUrl = "http://imgh.us/whiskyIceL.jpg",
                    InStock = false,
                    IsPreferredDrink = false,
                    ImageThumbnailUrl = "http://imgh.us/whiskeyS.jpg"
                },
                new Drink
                {
                    Name = "Jägermeister",
                    Price = 15.95M,
                    ShortDescription = "A German digestif made with 56 herbs",
                    LongDescription = "",
                    Category = Categories["Alcoholic"],
                    ImageUrl = "http://imgh.us/jagermeisterL.jpg",
                    InStock = false,
                    IsPreferredDrink = false,
                    ImageThumbnailUrl = "http://imgh.us/jagermeisterS.jpg"
                },
                new Drink
                {
                    Name = "Champagne",
                    Price = 15.95M,
                    ShortDescription = "That is how sparkling wine can be called",
                    LongDescription = "Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of de Finibus Bonorum et Malorum (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, comes from a line in section 1.10.32. The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from de Finibus Bonorum et Malorum by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.",
                    Category = Categories["Alcoholic"],
                    ImageUrl = "http://imgh.us/champagneL.jpg",
                    InStock = false,
                    IsPreferredDrink = false,
                    ImageThumbnailUrl = "http://imgh.us/champagneS.jpg"
                },
                new Drink
                {
                    Name = "Piña colada ",
                    Price = 15.95M,
                    ShortDescription = "A sweet cocktail made with rum.",
                    LongDescription = "Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of de Finibus Bonorum et Malorum (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, comes from a line in section 1.10.32. The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from de Finibus Bonorum et Malorum by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.",
                    Category = Categories["Alcoholic"],
                    ImageUrl = "http://imgh.us/pinaColadaL.jpg",
                    InStock = false,
                    IsPreferredDrink = false,
                    ImageThumbnailUrl = "http://imgh.us/pinaColadaS.jpg"
                },
                new Drink
                {
                    Name = "White Russian",
                    Price = 15.95M,
                    ShortDescription = "A cocktail made with vodka ",
                    LongDescription = "Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of de Finibus Bonorum et Malorum (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, comes from a line in section 1.10.32. The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from de Finibus Bonorum et Malorum by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.",
                    Category = Categories["Alcoholic"],
                    ImageUrl = "http://imgh.us/whiteRussianL.jpg",
                    InStock = false,
                    IsPreferredDrink = false,
                    ImageThumbnailUrl = "http://imgh.us/whiteRussianS.jpg"
                },
                new Drink
                {
                    Name = "Long Island Iced Tea",
                    Price = 15.95M,
                    ShortDescription = "Aa mixed drink made with tequila.",
                    LongDescription = "Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of de Finibus Bonorum et Malorum (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, comes from a line in section 1.10.32. The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from de Finibus Bonorum et Malorum by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.",
                    Category = Categories["Alcoholic"],
                    ImageUrl = "http://imgh.us/longTeaL.jpg",
                    InStock = false,
                    IsPreferredDrink = false,
                    ImageThumbnailUrl = "http://imgh.us/islandTeaS.jpg"
                },
                new Drink
                {
                    Name = "Vodka",
                    Price = 15.95M,
                    ShortDescription = "A distilled beverage with water and ethanol.",
                    LongDescription = "Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of de Finibus Bonorum et Malorum (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, comes from a line in section 1.10.32. The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from de Finibus Bonorum et Malorum by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.",
                    Category = Categories["Alcoholic"],
                    ImageUrl = "http://imgh.us/vodkaL.jpg",
                    InStock = false,
                    IsPreferredDrink = false,
                    ImageThumbnailUrl = "http://imgh.us/vodkaS.jpg"
                },
                new Drink
                {
                    Name = "Gin and tonic",
                    Price = 15.95M,
                    ShortDescription = "Made with gin and tonic water poured over ice.",
                    LongDescription = "Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of de Finibus Bonorum et Malorum (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, comes from a line in section 1.10.32. The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from de Finibus Bonorum et Malorum by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.",
                    Category = Categories["Alcoholic"],
                    ImageUrl = "http://imgh.us/ginTonicL.jpg",
                    InStock = false,
                    IsPreferredDrink = false,
                    ImageThumbnailUrl = "http://imgh.us/ginTonicS.jpg"
                },
                new Drink
                {
                    Name = "Cosmopolitan",
                    Price = 15.95M,
                    ShortDescription = "Made with vodka, triple sec, cranberry juice.",
                    LongDescription = "Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of de Finibus Bonorum et Malorum (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, comes from a line in section 1.10.32. The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from de Finibus Bonorum et Malorum by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.",
                    Category = Categories["Alcoholic"],
                    ImageUrl = "http://imgh.us/cosmopolitanL.jpg",
                    InStock = false,
                    IsPreferredDrink = false,
                    ImageThumbnailUrl = "http://imgh.us/cosmopolitanS.jpg"
                },
                new Drink
                {
                    Name = "Tea ",
                    Price = 12.95M,
                    ShortDescription = "Made by leaves of the tea plant in hot water.",
                    LongDescription = "Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of de Finibus Bonorum et Malorum (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, comes from a line in section 1.10.32. The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from de Finibus Bonorum et Malorum by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.",
                    Category = Categories["Non-alcoholic"],
                    ImageUrl = "http://imgh.us/teaL.jpg",
                    InStock = true,
                    IsPreferredDrink = true,
                    ImageThumbnailUrl = "http://imgh.us/teaS.jpg"
                },
                new Drink
                {
                    Name = "Water ",
                    Price = 12.95M,
                    ShortDescription = " It makes up more than half of your body weight ",
                    LongDescription = "Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of de Finibus Bonorum et Malorum (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, comes from a line in section 1.10.32. The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from de Finibus Bonorum et Malorum by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.",
                    Category = Categories["Non-alcoholic"],
                    ImageUrl = "http://imgh.us/waterL.jpg",
                    InStock = true,
                    IsPreferredDrink = false,
                    ImageThumbnailUrl = "http://imgh.us/waterS_1.jpg"
                },
                new Drink
                {
                    Name = "Coffee ",
                    Price = 12.95M,
                    ShortDescription = " A beverage prepared from coffee beans",
                    LongDescription = "Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of de Finibus Bonorum et Malorum (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, comes from a line in section 1.10.32. The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from de Finibus Bonorum et Malorum by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.",
                    Category = Categories["Non-alcoholic"],
                    ImageUrl = "http://imgh.us/coffeeL.jpg",
                    InStock = true,
                    IsPreferredDrink = true,
                    ImageThumbnailUrl = "http://imgh.us/coffeS.jpg"
                },
                new Drink
                {
                    Name = "Kvass",
                    Price = 12.95M,
                    ShortDescription = "A very refreshing Russian beverage",
                    LongDescription = "Contrary to popular belief, Lorem Bonorum et Malorum by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.",
                    Category = Categories["Non-alcoholic"],
                    ImageUrl = "http://imgh.us/kvassL.jpg",
                    InStock = true,
                    IsPreferredDrink = false,
                    ImageThumbnailUrl = "http://imgh.us/kvassS.jpg"
                },
                new Drink
                {
                    Name = "Juice ",
                    Price = 12.95M,
                    ShortDescription = "Naturally contained in fruit or vegetable tissue.",
                    LongDescription = "Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable accompanied by English versions from the 1914 translation by H. Rackham.",
                    Category = Categories["Non-alcoholic"],
                    ImageUrl = "http://imgh.us/juiceL.jpg",
                    InStock = true,
                    IsPreferredDrink = false,
                    ImageThumbnailUrl = "http://imgh.us/juiceS.jpg"
                }
            );
        }

        context.SaveChanges();
    }

    private static Dictionary<string, Category> categories;
    public static Dictionary<string, Category> Categories
    {
        get
        {
            if (categories == null)
            {
                var genresList = new Category[]
                {
                    new Category { CategoryName = "Alcoholic", Description="All alcoholic drinks" },
                    new Category { CategoryName = "Non-alcoholic", Description="All non-alcoholic drinks" }
                };

                categories = new Dictionary<string, Category>();

                foreach (Category genre in genresList)
                {
                    categories.Add(genre.CategoryName, genre);
                }
            }

            return categories;
        }
    }
}}

这是我的启动页面:

namespace DrinkAndGo
{
    public class Startup
    {
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit 
     https://go.microsoft.com/fwlink/?LinkID=398940

        private IConfigurationRoot _configurationRoot;

        public Startup(IHostingEnvironment hostingEnvironment)
        {
            _configurationRoot = new ConfigurationBuilder().SetBasePath(hostingEnvironment.ContentRootPath).AddJsonFile("appsettings.json").Build();
        }

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext<AppDbContext>(options => options.UseSqlServer(_configurationRoot.GetConnectionString("DefaultConnection")));
            services.AddTransient<IDrinkRepository, DrinkRepository>(); // Adding a service
            services.AddTransient<ICategoryRepository, CategoryRepository>(); // Adding a service
            services.AddMvc();
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            app.UseDeveloperExceptionPage();
            app.UseStatusCodePages();
            app.UseStaticFiles();
            app.UseMvcWithDefaultRoute();

            DbInitializer.Seed(app);
        }
    }
}

您可以从 IServiceProvider 解析 DbContextGetRequiredService<T> method.

将IServiceProvider作为参数添加到Startup类中的Configure方法中,运行时将为您注入它

public void Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider serviceProvider)
{
    app.UseDeveloperExceptionPage();
    app.UseStatusCodePages();
    app.UseStaticFiles();
    app.UseMvcWithDefaultRoute();

    DbInitializer.Seed(serviceProvider.GetRequiredService<AppDbContext>());
}

然后将AppDbContext作为参数添加到Seed方法中

public static void Seed(AppDbContext context)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

InvalidOperationException:无法解析范围服务 的相关文章

  • 使用和重载基类的模板成员函数?

    下面 构造Y超载X的成员函数f 两个重载都是模板函数 但采用不同的参数 typename and int 明确指定 struct X template
  • 替换大字符串中的多个字符串的最快方法

    我正在寻找替换大 1mb 字符串的多个 500 子字符串的最快方法 无论我尝试过什么 String Replace 似乎都是最快的方法 我只关心最快的方式 不是代码的可读性 可维护性等 我不在乎是否需要使用不安全的代码或预处理原始字符串 每
  • 可以作为参数传递给 POST 方法的对象的最大大小

    我有一个带有 POST 方法的 Web API 控制器 如下所示 public class MyController ApiController POST api Scoring public HttpResponseMessage Pos
  • 使用 C# 将文件列表从 ftp 下载到本地文件夹? [复制]

    这个问题在这里已经有答案了 我希望将 ftp 中的所有文件下载到本地文件夹 下载到本地驱动器后 所有文件都应在 ftp 中删除 从下面的代码 我只能从 ftp 下载一个我不期望的文件 我需要将所有文件放在一个文件夹中 但不放在本地文件名的名
  • 如何向 Iron Python 添加模块?

    我一直在尝试使用 C Visual Studio 执行以下 Python 代码 graphcreater py 我通过 NuGet 包管理器添加了 IronPyton 2 7 7 和 IronPython StdLib 2 7 7 一旦我运
  • main() 是用户定义函数吗? [复制]

    这个问题在这里已经有答案了 程序员does定义内部发生的事情main 毕竟 那么 它应该被视为用户定义的函数吗 C 标准没有用户定义函数的概念 相反 它有一个概念库函数 main 不是库函数 但是 该标准还对其签名提出了一些要求 并且不得重
  • 创建一个从用户机密获取连接字符串的 DbContextFactory

    使用 DotNetCore 解决方案WebApi项目和一个单独的Data包含实体框架实现的项目 我们一直在升级库 因此我们使用所有最新的核心内容 In the Data项目 我们创建了一个ApplicationDbContextFactor
  • C# 中的 memcpy 函数 [重复]

    这个问题在这里已经有答案了 可能的重复 C memcpy 等效项 https stackoverflow com questions 510971 c memcpy equivalent 相当于什么memcpyC 中的函数 正如已经说过的
  • StreamReader 的默认值是多少?

    我需要使用这个构造函数public StreamReader Stream stream Encoding encoding bool detectEncodingFromByteOrderMarks int bufferSize bool
  • CMake include_directories 和 add_subdirectories 之间的区别?

    我正在学习 CMake 来构建 C 代码 并努力解决以下概念 在我的根级目录中 我有一些 cpp 文件和 CMakeLists txt 它们在 gen cpp 目录中成功生成了一些 thrift 代码 我的根级别 CMakeLists tx
  • 如何重命名 MacOS/X 程序中的程序名称菜单标签?

    我有一个在 MacOS X 下运行的基于 Qt 的 GUI 程序 我希望能够更改该程序的第一个菜单标题的标签 即此屏幕截图中用红色圈出的标签 有没有一种编程方法可以做到这一点 假设不存在基于 Qt 的解决方案 则 Objective C 本
  • C++ 中的结构填充

    如果我有一个struct在 C 中 有没有办法安全地将其读 写到跨平台 编译器兼容的文件中 因为如果我理解正确的话 每个编译器都会根据目标平台进行不同的 填充 不 那是不可能的 这是因为C 在二进制层面缺乏标准化 Don Box http
  • 提供的 URI 方案“https”无效;预期为“http”。参数名称:via

    我使用了下面没有 https 的配置 现在网址改为 https 但我越来越 提供的 URI 方案 https 无效 需要 http 参数名称 via 调用时出错
  • 网页上的富文本编辑器

    我正在尝试在我的网页中添加一个富文本编辑器 用户可以在其中撰写评论并格式化他们所写的内容 类似于我们在此网站上撰写帖子的编辑器 谁能指出我关于此的正确方向 任何可以帮助我构建这样一个组件的教程 我还想要一个免费的产品 忘记之前提到 类似的东
  • Docker 在 VS 中运行,但发布到 AWS 时出错?错误 CS5001:程序不包含适合入口点的静态“Main”方法

    我安装了适用于 Visual Studio 2017 V15 7 3 的 AWS 工具包 并使用 API 模板和 Linux docker 支持创建了一个新的空 Asp Net core 2 1 项目 我可以在 Visual Studio
  • 在 QML 中使用 C++ 枚举作为字符串

    我想做的是在 C 中使用以下枚举 class MyClass public QQuickItem Q OBJECT Q PROPERTY MyEnum enumValue READ getEnumValue public enum MyEn
  • 当调试器退出且没有调用堆栈时,用于跟踪 C# 崩溃的工具?

    我有一个大型 复杂的 C GUI 应用程序 它以完全可重现的方式崩溃 但我无法轻松诊断崩溃的原因 因为调试会话不是以通常的方式使用调用堆栈破坏调试器 而是完全退出 唯一的提示是输出窗口末尾有一条消息 STATUS STACK BUFFER
  • MVC - 从视图调用控制器

    我是 MVC 新手 我正在使用 MVC 开发一个 Web 应用程序 该应用程序仅包含一个页面 所以在这个视图中我必须填充多个数据 假设应用程序是 新闻提要 应用程序 我需要填充最近的新闻 您喜欢的新闻 您朋友推荐的新闻等 那么我应该从视图到
  • 我使用 difftime 的 c 函数有时会返回 65535

    我有一个函数 使用 difftime 来检测自通信心跳停止以来的时间 以秒为单位 该函数的运行速度可以达到每 50 毫秒一次 该函数似乎可以工作 除了偶尔返回 65535 之外 我可以将执行次数减少到每秒一次 因为 difftime 的返回
  • 在字典和集合上自动添加索引器是一个好的设计决策吗?

    索引器何时可以自动将项目添加到集合 字典中 这是合理的还是违反最佳实践的 public class I snip public class D Dictionary

随机推荐