ipjohnson / Grace

Grace is a feature rich dependency injection container library
MIT License
336 stars 33 forks source link

Locate not properly using ExtraData #313

Open JBurlison opened 11 months ago

JBurlison commented 11 months ago

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)
JBurlison commented 11 months ago

The exact spot if context is needed: The registration: https://github.com/ForgedWoW/WrathForgedCore/blob/main/WrathForged.Authorization.Server/DependancyInjection.cs#L15

The constructor: https://github.com/ForgedWoW/WrathForgedCore/blob/main/WrathForged.Common/WoWClientSession.cs#L15

Where the exception is being thrown: https://github.com/ForgedWoW/WrathForgedCore/blob/main/WrathForged.Common/Networking/WoWClientServer.cs#L138

JBurlison commented 11 months ago

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?