ipjohnson / Grace

Grace is a feature rich dependency injection container library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Locate not properly using ExtraData

JBurlison opened this issue · comments

I am getting an exception on this line:

e.Client.ClientSession = _container.Locate<IClientSession>(new { clientSocket = e.Client });

I am registering my object:

_ = builder.Export<ClientSession>().As<IClientSession>();

And my constructor

public ClientSession(ClientSocket clientSocket, PacketBuffer packetBuffer, ClassFactory classFactory)

I am giving it the clientSocket object but its trying to construct it.

Here is the constructor of that. Notice the first parameter is TcpClient.

public ClientSocket(TcpClient client, ILogger logger, ActionBlock<DataReceivedEventArgs> actionBlock)

From the looks of the error, its attempting to construct the TcpClient for the ClientSocket even though I passed it in with my extra data.

2023-10-16 04:37:16.749 -04:00 [ERR] Error processing data from client
System.ArgumentException: An invalid IP address was specified. (Parameter 'address')
   at System.Net.IPAddress..ctor(ReadOnlySpan`1 address)
   at lambda_method1067(Closure, IExportLocatorScope, IDisposalScope, IInjectionContext)
   at Grace.DependencyInjection.Impl.InjectionScope.InternalLocate(IExportLocatorScope scope, IDisposalScope disposalScope, Type type, ActivationStrategyFilter consider, Object key, IInjectionContext injectionContext, Boolean allowNull, Boolean isDynamic)
   at Grace.DependencyInjection.Impl.InjectionScope.Grace.DependencyInjection.IInjectionScope.LocateFromChildScope(IExportLocatorScope childScope, IDisposalScope disposalScope, Type type, Object extraData, ActivationStrategyFilter consider, Object key, Boolean allowNull, Boolean isDynamic)
   at Grace.DependencyInjection.Impl.ActivationStrategyDelegateCache.FallbackExecution(ImmutableHashTree`2 currentNode, Type type, IExportLocatorScope scope, Boolean allowNull, IInjectionContext context)
   at Grace.DependencyInjection.Impl.ActivationStrategyDelegateCache.ExecuteActivationStrategyDelegateWithContext(Type type, IExportLocatorScope scope, Boolean allowNull, IInjectionContext context)
   at Grace.DependencyInjection.Impl.InjectionScope.Locate(Type type, Object extraData, ActivationStrategyFilter consider, Object withKey, Boolean isDynamic)
   at Grace.DependencyInjection.Impl.InjectionScope.Locate[T](Object extraData, ActivationStrategyFilter consider, Object withKey, Boolean isDynamic)

Looks like its not properly using my extra data as an override object, its opting to try and create the ClientSocket and part of the constructor for ClientSocket is a TCPClient and that needs a IPAddress.

Is there a way to not have grace try and construct this or is it a bug?