VictorTzeng / Zxw.Framework.NetCore.Demo

Demo for the Zxw.Framework.NetCore repository.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

一个项目工程没找到,是不是忘记删了?

programClown opened this issue · comments

Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Zxw.Framework.NetCore", "....\Zxw.Framework.NetCore\Zxw.Framework.NetCore\Zxw.Framework.NetCore.csproj", "{68D83A38-C0B1-466A-8C89-9ECDD90F622C}"
EndProject

我说错了,是目前依赖的原工程Zxw.Framework.NetCore,目前这个demo没有用nuget加载Zxw.Framework.NetCore

commented

抱歉,我的锅,之前本地测试CAP忘记删了,现在已经改了,重新拉一下

好的,还有能不能支持sqlite3数据库啊,还有swagger api支持,要求过分的话您也可以无视,哈哈

异常报错
return services.AddCoreX(config => { config.AddSingleton<IWebContext, DemoWebContext>(); }, aspectConfig => { aspectConfig.Interceptors.AddTyped<FromDbContextFactoryInterceptor>(); });//接入AspectCore.Injector

System.TypeLoadException
HResult=0x80131522
Message=Method 'Remove' in type 'AspectCore.DependencyInjection.ServiceContext' from assembly 'AspectCore.Core, Version=2.0.0.0, Culture=neutral, PublicKeyToken=2ab7daa5defcf11f' does not have an implementation.
Source=AspectCore.Extensions.DependencyInjection
StackTrace:
at AspectCore.Extensions.DependencyInjection.ServiceCollectionToServiceContextExtensions.ToServiceContext(IServiceCollection services)
at Zxw.Framework.NetCore.IoC.AspectCoreContainer.BuildServiceProvider(IServiceCollection services, Action1 configure) at Zxw.Framework.NetCore.Extensions.ServiceExtension.BuildAspectCoreServiceProvider(IServiceCollection services, Action1 configure)
at Zxw.Framework.NetCore.Extensions.ServiceExtension.AddCoreX(IServiceCollection services, Action1 config, Action1 aspectConfig)
at Zxw.Framework.Website.Startup.InitIoC(IServiceCollection services) in D:\VS2019\Zxw.Framework.NetCore.Demo\src\Zxw.Framework.Website\Startup.cs:line 165
at Zxw.Framework.Website.Startup.ConfigureServices(IServiceCollection services) in D:\VS2019\Zxw.Framework.NetCore.Demo\src\Zxw.Framework.Website\Startup.cs:line 40
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.InvokeCore(Object instance, IServiceCollection services)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass9_0.g__Startup|0(IServiceCollection serviceCollection)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.Invoke(Object instance, IServiceCollection services)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass8_0.b__0(IServiceCollection services)
at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.UseStartup(Type startupType, HostBuilderContext context, IServiceCollection services)
at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass12_0.b__0(HostBuilderContext context, IServiceCollection services)
at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()
at Microsoft.Extensions.Hosting.HostBuilder.Build()
at Zxw.Framework.Website.Program.Main(String[] args) in D:\VS2019\Zxw.Framework.NetCore.Demo\src\Zxw.Framework.Website\Program.cs:line 11

commented

能支持sqlite3数据库啊

要实现sqlite3的话,很简单,自己写个SqliteDbContext继承BaseContext,然后实现某些特定的函数就OK了

commented

异常报错
return services.AddCoreX(config => { config.AddSingleton<IWebContext, DemoWebContext>(); }, aspectConfig => { aspectConfig.Interceptors.AddTyped<FromDbContextFactoryInterceptor>(); });//接入AspectCore.Injector

System.TypeLoadException
HResult=0x80131522
Message=Method 'Remove' in type 'AspectCore.DependencyInjection.ServiceContext' from assembly 'AspectCore.Core, Version=2.0.0.0, Culture=neutral, PublicKeyToken=2ab7daa5defcf11f' does not have an implementation.
Source=AspectCore.Extensions.DependencyInjection
StackTrace:
at AspectCore.Extensions.DependencyInjection.ServiceCollectionToServiceContextExtensions.ToServiceContext(IServiceCollection services)
at Zxw.Framework.NetCore.IoC.AspectCoreContainer.BuildServiceProvider(IServiceCollection services, Action1 configure) at Zxw.Framework.NetCore.Extensions.ServiceExtension.BuildAspectCoreServiceProvider(IServiceCollection services, Action1 configure)
at Zxw.Framework.NetCore.Extensions.ServiceExtension.AddCoreX(IServiceCollection services, Action1 config, Action1 aspectConfig)
at Zxw.Framework.Website.Startup.InitIoC(IServiceCollection services) in D:\VS2019\Zxw.Framework.NetCore.Demo\src\Zxw.Framework.Website\Startup.cs:line 165
at Zxw.Framework.Website.Startup.ConfigureServices(IServiceCollection services) in D:\VS2019\Zxw.Framework.NetCore.Demo\src\Zxw.Framework.Website\Startup.cs:line 40
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.InvokeCore(Object instance, IServiceCollection services)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass9_0.g__Startup|0(IServiceCollection serviceCollection)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.Invoke(Object instance, IServiceCollection services)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass8_0.b__0(IServiceCollection services)
at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.UseStartup(Type startupType, HostBuilderContext context, IServiceCollection services)
at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass12_0.b__0(HostBuilderContext context, IServiceCollection services)
at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()
at Microsoft.Extensions.Hosting.HostBuilder.Build()
at Zxw.Framework.Website.Program.Main(String[] args) in D:\VS2019\Zxw.Framework.NetCore.Demo\src\Zxw.Framework.Website\Program.cs:line 11

这个估计是AspectCore升级至最新的锅,晚上回去了我瞅瞅。或者你可以先解决,然后提交PR

好的,我研究一下

commented

好的,我研究一下

已更新

程序可以运行了,发现个新问题,
"MySQL": "Server=localhost;Database=NetCoreDemo; User ID=root;Password=xxxxxxx;port=3306;CharSet=utf8;pooling=true;"
我把MySQL配置好以后,修改database为
//database connectionstring var dbConnectionString = Configuration.GetConnectionString("MySQL");
数据库迁移报错,
PM> Add-Migration InitialCreate Build started... Build succeeded. Your target project 'Zxw.Framework.Website.Models' doesn't match your migrations assembly 'Zxw.Framework.NetCore'. Either change your target project or change your migrations assembly. Change your migrations assembly by using DbContextOptionsBuilder. E.g. options.UseSqlServer(connection, b => b.MigrationsAssembly("Zxw.Framework.Website.Models")). By default, the migrations assembly is the assembly containing the DbContext. Change your target project to the migrations project by using the Package Manager Console's Default project drop-down list, or by executing "dotnet ef" from the directory containing the migrations project. PM>
把下边的仓储注入修改MySqlDbContext后还是报错
`services.AddSingleton(Configuration)//注入Configuration,ConfigHelper要用
//.AddScoped<IDbContextCore, PostgreSQLDbContext>()//注入EF上下文
//.AddDbContext<IDbContextCore, SqlServerDbContext>()//注入EF上下文

.AddDbContextFactory(factory =>
{
factory.AddDbContext<IDbContextCore, MySqlDbContext>(
new DbContextOption()
{
TagName = "db1",
ConnectionString = dbConnectionString,
ModelAssemblyName = "Zxw.Framework.Website.Models",
IsOutputSql = true
});
})
.AddScopedAssembly("Zxw.Framework.Website.IRepositories", "Zxw.Framework.Website.Repositories");//注入仓储`

commented

数据库迁移这块还没考虑,目前方式比较粗暴,测试环境就删了重新来。。

那样的话能不能给一个MySQL的SQL文件,我手动导入也没事,好多go项目也手动导入一个初始的SQL文件,这样也方便一点,谢谢,另外,切换数据库就Configuration.GetConnectionString("MySQL");factory.AddDbContext<IDbContextCore, MySqlDbContext>这两处即可吧

commented

你是要导入数据还是同步数据结构?切换数据库就是这样操作,可以把AddDbContextFactory去掉,这是针对多数据库连接

嗯,我是想用MySQL,现在的情况是我只有MySQL,没有postgreSQL,切换完Configuration.GetConnectionString("MySQL");修改完appsettings.json的MySQL配置后,运行起来没有起效,配置的"MySQL": "Server=localhost;Database=NetCoreDemo; User ID=root;Password=xxxxxxx;port=3306;CharSet=utf8;pooling=true;"这个NetCoreDemo db没有创建,登陆失败

commented

把Models项目里面所有实体类上面的[DbContext(typeof(SqlServerDbContext))]属性标记改成你对应的数据库DbContext。比如,改成[DbContext(typeof(MySqlDbContext))]

好了,我手动建表,可以执行了,谢谢