StructureMap and passing a null parameter to an instance

I create an instance with StructureMap in the code, and the constructor takes a string. In the configuration, I use a placeholder for the parameter. I am trying to create an object with a null parameter value. When I return an object from an ObjectFactory, the value of the parameter is equal to the placeholder, not null.

here is my configuration for the object:

<DefaultInstance PluginType="Blah.NDQA.Core.Data.IUserManagementRepository,Blah.NDQA.Core" PluggedType="Blah.NDQA.Data.MySql.MySqlUserManagementRepository,Blah.NDQA.Data" companyID="placeholder"/>

this is how i create it:

IUserRightsRepository rightsRepo = ObjectFactory.With("companyID").EqualTo(null).GetInstance<IUserRightsRepository>();

in the specific case, companyID = null, and the value in the instance is "placeholder".

Any information on how I can actually create an object with companyID = null instead of placeholder will be appreciated ....

+1
source share
1 answer

Try:

ObjectFactory.With<string>(null).GetInstance<IUserRightsRepository>();
+1
source

Source: https://habr.com/ru/post/1748550/


All Articles