Tag: light inject

LightInject IoC容器在解析类型时抛出stackoverflow

在尝试LightInject IoC容器http://www.lightinject.net/时,它会在解析ISomeService类型时抛出stackoverflowexception: 所有类型都在App_Start中注册: container.RegisterAssembly(“MyApp*.dll”); 然后,当我尝试在控制器中解决它时,它会失败并抛出stackoverflowexception: public SomeController(ISomeService someService) { _someService = someService; } 使用ServiceLocator时也会出现相同的错误: ServiceLocator.Current.GetInstance(); 我已经跟踪了它,我可以看到它在LightInject ServiceContainer类中失败了,但是我不明白为什么它失败了。 public object GetInstance(Type serviceType) { return GetDefaultDelegate(serviceType, true)(constants.Items); } 在调用GetDefaultDelegate之后,执行路径再次在GetInstance中结束,导致无限循环和堆栈溢出。 编辑2 – 已进一步跟踪此问题,它似乎是由SomeService同时具有构造函数和属性注入引起的: public class SomeService : ISomeService { public IAnotherService AnotherService { get; set; } public SomeService(IAnotherService anotherService) { AnotherService = anotherService; } } 依赖IAnotherService AnotherService是通过构造函数和属性注入的,但是无意使用属性注入器。 编辑3 […]

SignalR服务器 – >客户端呼叫无法正常工作

我目前正在使用SignalR在服务器和服务器本身产生的多个独立进程之间进行通信。 Server和Client都用C#编码。 我正在使用SignalR 2.2.0.0在服务器端,我使用OWIN来运行服务器。 我也使用LightInject作为IoC容器。 这是我的代码: public class AgentManagementStartup { public void ConfigurationOwin(IAppBuilder app, IAgentManagerDataStore dataStore) { var serializer = new JsonSerializer { PreserveReferencesHandling = PreserveReferencesHandling.Objects, TypeNameHandling = TypeNameHandling.Auto, TypeNameAssemblyFormat = FormatterAssemblyStyle.Simple }; var container = new ServiceContainer(); container.RegisterInstance(dataStore); container.RegisterInstance(serializer); container.Register(); container.Register(); var config = container.EnableSignalR(); app.MapSignalR(“”, config); } } 在客户端,我这样注册: public async Task Connect() […]