Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

作者你好,Repository+UnitOfWork 用autofac好像有问题。 #350

Closed
ElvenP opened this issue Jun 18, 2020 · 15 comments
Closed

作者你好,Repository+UnitOfWork 用autofac好像有问题。 #350

ElvenP opened this issue Jun 18, 2020 · 15 comments

Comments

@ElvenP
Copy link

ElvenP commented Jun 18, 2020

No description provided.

@2881099
Copy link
Collaborator

2881099 commented Jun 18, 2020

是什么问题,#289 有没有看这个

@ElvenP
Copy link
Author

ElvenP commented Jun 18, 2020

Duplicate of #

是什么问题,#289有没有看这个

首先感觉作者的回复,并且是这么快的回复。
2
3
4
5
6
7
1
大概的流程就是这样。最后一张图就是报错的。没有注入成功。
然后我的项目中还使用了autofac。我想是不是由于与asp.net core 本身的注入有冲突。
于是我写在了autofac里面。。如下图
8

@2881099
Copy link
Collaborator

2881099 commented Jun 18, 2020

builder.RegisterType<IFreeSql> 这样是对的吗,单例,还需要指定实例 fsql。

前面的错误,提示没有注入 UnitOfWorkManager,但是前面的代码看着是注入了?

@ElvenP
Copy link
Author

ElvenP commented Jun 18, 2020

builder.RegisterType 这样是对的吗,单例,还需要指定实例 fsql。

前面的错误,提示没有注入 UnitOfWorkManager,但是前面的代码看着是注入了?
注入了,在第六张图里注入了。另外

builder.RegisterType<IFreeSql我只是写了个例子,并没在autofac中使用

@2881099
Copy link
Collaborator

2881099 commented Jun 18, 2020

看前面的注入使用的是MS自带的DI的注入,没有看到 autofac 代码。

是不是从 IServiceCollection 转 autofac 的时候丢失了,在 .net core3.x 还能这样用吗

@ElvenP
Copy link
Author

ElvenP commented Jun 18, 2020 via email

@2881099
Copy link
Collaborator

2881099 commented Jun 18, 2020

能否整理一个简单demo上传一下?

@ElvenP
Copy link
Author

ElvenP commented Jun 18, 2020 via email

@2881099
Copy link
Collaborator

2881099 commented Jun 18, 2020

问题一:版本不一致,应该都用一样的版本(Admin.Core.Common.csproj)

      <PackageReference Include="FreeSql" Version="1.6.0-preview0611" />
      <PackageReference Include="FreeSql.Provider.SqlServer" Version="1.5.0" />
      <PackageReference Include="FreeSql.Repository" Version="1.6.0-preview0611" />

@2881099
Copy link
Collaborator

2881099 commented Jun 18, 2020

image

运行OK,没有出现说的注入错误

@2881099
Copy link
Collaborator

2881099 commented Jun 18, 2020

image

在 UserService.GetAsync 方法上增加 [Transaction] 特性后,事务也生效了。

@ElvenP
Copy link
Author

ElvenP commented Jun 18, 2020 via email

@2881099
Copy link
Collaborator

2881099 commented Jun 18, 2020

直接用控制台运行呢,dotnet run

@ElvenP
Copy link
Author

ElvenP commented Jun 18, 2020 via email

@ElvenP ElvenP closed this as completed Jun 18, 2020
@2881099
Copy link
Collaborator

2881099 commented Jun 18, 2020

谢谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants