diff --git a/backend/IM_API/Configs/ServiceCollectionExtensions.cs b/backend/IM_API/Configs/ServiceCollectionExtensions.cs new file mode 100644 index 0000000..b7ee2c6 --- /dev/null +++ b/backend/IM_API/Configs/ServiceCollectionExtensions.cs @@ -0,0 +1,10 @@ +namespace IM_API.Configs +{ + public static class ServiceCollectionExtensions + { + public static IServiceCollection AddAllService(this IServiceCollection services, IConfiguration configuration) + { + return services; + } + } +} diff --git a/backend/IM_API/Dtos/TestDto.cs b/backend/IM_API/Dtos/TestDto.cs new file mode 100644 index 0000000..bd689d6 --- /dev/null +++ b/backend/IM_API/Dtos/TestDto.cs @@ -0,0 +1,8 @@ +namespace IM_API.Dtos +{ + public class TestDto + { + public int Id { get; set; } + public string Name { get; set; } + } +} diff --git a/backend/IM_API/Interface/Services/IDemo.cs b/backend/IM_API/Interface/Services/IDemo.cs new file mode 100644 index 0000000..75bf461 --- /dev/null +++ b/backend/IM_API/Interface/Services/IDemo.cs @@ -0,0 +1,9 @@ +using IM_API.Dtos; + +namespace IM_API.Interface.Services +{ + public interface IDemo + { + TestDto Test(); + } +} diff --git a/backend/IM_API/Models/IMDbContext.cs b/backend/IM_API/Models/IMDbContext.cs index 39bc38f..5215258 100644 --- a/backend/IM_API/Models/IMDbContext.cs +++ b/backend/IM_API/Models/IMDbContext.cs @@ -50,10 +50,6 @@ public partial class IMDbContext : DbContext public virtual DbSet Users { get; set; } - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) -#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see https://go.microsoft.com/fwlink/?LinkId=723263. - => optionsBuilder.UseMySql("server=192.168.5.100;port=3306;database=IM;user=root;password=768788Dyw", Microsoft.EntityFrameworkCore.ServerVersion.Parse("5.7.44-mysql")); - protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder diff --git a/backend/IM_API/Program.cs b/backend/IM_API/Program.cs index 96341b4..e906aee 100644 --- a/backend/IM_API/Program.cs +++ b/backend/IM_API/Program.cs @@ -1,4 +1,8 @@ +using IM_API.Configs; +using IM_API.Models; +using Microsoft.EntityFrameworkCore; + namespace IM_API { public class Program @@ -8,7 +12,17 @@ namespace IM_API var builder = WebApplication.CreateBuilder(args); // Add services to the container. + IConfiguration configuration = new ConfigurationBuilder() + .SetBasePath(Directory.GetCurrentDirectory()) + .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) + .Build(); + string conStr = builder.Configuration.GetConnectionString("DefaultConnection")!; + builder.Services.AddDbContext(options => + { + options.UseMySql(conStr,ServerVersion.AutoDetect(conStr)); + }); + builder.Services.AddAllService(configuration); builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); diff --git a/backend/IM_API/Services/Demo.cs b/backend/IM_API/Services/Demo.cs new file mode 100644 index 0000000..4c12ef6 --- /dev/null +++ b/backend/IM_API/Services/Demo.cs @@ -0,0 +1,13 @@ +using IM_API.Dtos; +using IM_API.Interface.Services; + +namespace IM_API.Services +{ + public class Demo : IDemo + { + public TestDto Test() + { + throw new NotImplementedException(); + } + } +} diff --git a/backend/IM_API/appsettings.json b/backend/IM_API/appsettings.json index 10f68b8..eb0a86a 100644 --- a/backend/IM_API/appsettings.json +++ b/backend/IM_API/appsettings.json @@ -5,5 +5,8 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + "ConnectionStrings": { + "DefaultConnection": "Server=192.168.5.100;Port=3306;Database=IM;User=root;Password=768788Dyw;" + } }