Trong quá trình làm dự án chắc hẳn bạn cũng đã có lúc cần test thử function mình viết mà không cần phải run cả 1 dự án cồng kềnh. Đó chính là lúc console app phát huy tác dụng.
Các bạn có thể tạo 1 console app và Inject service mình cần debug vào như sau
using Microsoft.Extensions.DependencyInjection; static async Task Main(string[] args) { try { //setup our DI var serviceProvider = new ServiceCollection() .AddScoped<IStoreProcedureLogic<GenericVM, GenericEntity>, StoreProcedureLogic<GenericVM, GenericEntity>>() .AddDbContext<WorkingPaperDbContext>(options => { options.UseSqlServer("Server=YOUR-SERVER;Database=YourDatabaseName;Trusted_Connection=True;"); options.LogTo(Console.WriteLine, Microsoft.Extensions.Logging.LogLevel.Information); }) .BuildServiceProvider(); // Get service all call var storeLogic = serviceProvider.GetService<IStoreProcedureLogic<GenericVM, GenericEntity>>(); var data = storeLogic.GetAll(); } catch{} }
Như vậy là bạn có thể đặt debug vào function GetAll() của mình rồi đấy.