You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello guys! First of all special thanks to the main developer @seesharper and other contributors.
But unfortunately I have a small problem in my code on one of the VMs (Hyper-V) and IIS. Initial
Using:
LightInject version="6.2.0"
LightInject.Mvc version="2.0.0"
LightInject.Web version="2.0.0"
Target framework: 4.7.2 (try on 4.8 - similarly)
Project: ASP.NET MVC 5.2.7
My IoC container:
` public static class IoCConfig
{
internal static readonly ServiceContainer Container = new ServiceContainer();
And in one of the controllers using Property Injection for inject ICommandFactory and call with CreateCommand:
CommandFactory.Execute(createCommand);
In CreateCommandHandler class using constructor injection DBConnection and IUrlCreator. In implementation UrlCreator class using constructor injection for DBConnection.
Easier to show on the diagram:
And i was hoping to get the same one DBConnection in UrlCreator and CreateCommandHandler because they both PerScope (after i used extensions Web and MVC = ByWebRequest).
But unfortunately I have a two different instances of DBConnection in my logs. After that I noticed that if you add a line in constructor of UrlCreator _logger.Write(Environment.StackTrace);
Then the stack is displayed correctly and the instance is the same for both classes! MAGIC!
At first I sinned against the asynchrony (async-await) of the MVC controller method, but i try and sync version - the problem didn't go away:(
I checked, scope is the same (GetHashCode), HttpContex too, ThreadId (Thread.ManagedThreadId) too! But DbConnection - two different instances.
Maybe, you will help me guys? Please:)
The text was updated successfully, but these errors were encountered:
Nelo-cool
changed the title
Two difference DBConnection in one scope for WebRequest (MVC).
Two different DBConnection in one scope for WebRequest (MVC).
Jan 27, 2020
New magic: If I use a container.GetInstanse<IEnumerable<ICommandHandler>>(), then everything is fine for a few hours, but then the error returns. Very strange:(
Hello guys! First of all special thanks to the main developer @seesharper and other contributors.
But unfortunately I have a small problem in my code on one of the VMs (Hyper-V) and IIS.
Initial
Using:
Target framework: 4.7.2 (try on 4.8 - similarly)
Project: ASP.NET MVC 5.2.7
My IoC container:
` public static class IoCConfig
{
internal static readonly ServiceContainer Container = new ServiceContainer();
}`
After i am call RegisterIoC method of IoCConfig class from Global.asax with:
Container.RegisterControllers(); Container.EnableMvc();
And in one of the controllers using Property Injection for inject ICommandFactory and call with CreateCommand:
CommandFactory.Execute(createCommand);
In CreateCommandHandler class using constructor injection DBConnection and IUrlCreator. In implementation UrlCreator class using constructor injection for DBConnection.
Easier to show on the diagram:
![http://imagecdn.ru/call_tree_for_question.png](https://camo.githubusercontent.com/ff6b20b6bb86d5216052a9d0694be44fbbd3baa1060c35778ba7f065b7124ba3/687474703a2f2f696d61676563646e2e72752f63616c6c5f747265655f666f725f7175657374696f6e2e706e67)
And i was hoping to get the same one DBConnection in UrlCreator and CreateCommandHandler because they both PerScope (after i used extensions Web and MVC = ByWebRequest).
But unfortunately I have a two different instances of DBConnection in my logs. After that I noticed that if you add a line in constructor of UrlCreator
_logger.Write(Environment.StackTrace);
Then the stack is displayed correctly and the instance is the same for both classes! MAGIC!
At first I sinned against the asynchrony (async-await) of the MVC controller method, but i try and sync version - the problem didn't go away:(
I checked, scope is the same (GetHashCode), HttpContex too, ThreadId (Thread.ManagedThreadId) too! But DbConnection - two different instances.
Maybe, you will help me guys? Please:)
The text was updated successfully, but these errors were encountered: