顯示具有 .NetCore 標籤的文章。 顯示所有文章
顯示具有 .NetCore 標籤的文章。 顯示所有文章

2019年11月26日 星期二

新增 net core project


$ dotnet new web -o <專案名稱>
dotnet help 可以查看專案型態的參數
安裝npm $ npm install 檢查npm安裝版本
$ npm -v

init npm
$npm init
如果沒有要設定專案資訊 直接Enter到底
結束之後 會再package.json寫入設定

npm安裝套件 ex jquery
$ npm install jquery

安裝LibMan
$ dotnet tool install -g Microsoft.Web.LibraryManager.Cli

Run
$ dotnet run


Ref microsoft microsoft-SingleR install

2019年11月24日 星期日

.Net Core Console使用依賴注入

public static async Task Main(string[] args)
{

     // 取得設定檔
      IConfiguration config = new ConfigurationBuilder()
                             .AddJsonFile("appsettings.json", true, true)
                             .Build();
    // 建立容器
    var serviceCollection = new ServiceCollection();

    // 註冊服務
    serviceCollection.AddTransient();
    serviceCollection.AddTransient();

    // 加入SqlServer 連線字串
    serviceCollection.AddDbContext(options => options.UseSqlServer(config["ConnectionStrings:DefaultConnection"]));

    // 建立依賴服務提供者
    var serviceProvider = serviceCollection.BuildServiceProvider();

    // 執行
    await serviceProvider.GetRequiredService().Run();
}