Closed scovel closed 6 years ago
Hi @scovel,
I’ll find some examples tonight showing how to do this. Essentially it’s just adding a couple WithCtorParam configurations to the Export call.
I realized there was no method to register what you wanted to do so I added a new method and will do a nuget pre-release for it.
Case 1:
container.Configure(c =>
c.Export<MemorizingMappingManager>().As<IReadOnlyMappingManager>().
WithCtorParam<IReadOnlyMappingManager>().Use(typeof(AttributesMappingManager)));
Case 2:
if(registrationId == null)
{
container.Configure(c =>
c.Export(SolrQueryExecuter).As(ISolrQueryExecuter).
WithCtorParam(typeof(ISolrConnection)).LocateWithKey(coreConnectionId));
}
else
{
container.Configure(c =>
c.Export(SolrQueryExecuter).AsKeyed(ISolrQueryExecuter, registrationId).
WithCtorParam(typeof(ISolrConnection)).LocateWithKey(coreConnectionId));
}
That is working!!!
I owe you so many beers....
So, follow-up question. I need to set an injection property at the same time. Unity was using InjectionProperty. I looked at ImportMembers but couldn't figure out how to set a specific value.
.ImportMembers(MembersThat.AreNamed("HttpWebRequestFactory"))
Looking at the property in the library there is no specific injection attributes on it, it's just a public property.
/// <summary>
/// HTTP request factory
/// </summary>
public IHttpWebRequestFactory HttpWebRequestFactory { get; set; }
Here's the Unity code:
container.RegisterType<ISolrConnection, SolrConnection>("solr" + typeof(SolrConnection),
new InjectionMember[] { new InjectionConstructor("http://localhost:8983/solr"),
new InjectionProperty("HttpWebRequestFactory", new BasicAuthHttpWebRequestFactory("user", "pass")) });
Now, why they didn't just add an overloaded constructor, I have no idea...
That is working!!!
I owe you so many beers....
So, follow-up question. I need to set an injection property at the same time. Unity was using InjectionProperty. I looked at ImportMembers but couldn't figure out how to set a specific value.
.ImportMembers(MembersThat.AreNamed("HttpWebRequestFactory"))
Looking at the property in the library there is no specific injection attributes on it, it's just a public property.
/// <summary>
/// HTTP request factory
/// </summary>
public IHttpWebRequestFactory HttpWebRequestFactory { get; set; }
Here's the Unity code:
container.RegisterType<ISolrConnection, SolrConnection>("solr" + typeof(SolrConnection),
new InjectionMember[] { new InjectionConstructor("http://localhost:8983/solr"),
new InjectionProperty("HttpWebRequestFactory", new BasicAuthHttpWebRequestFactory("user", "pass")) });
Now, why they didn't just add an overloaded constructor, I have no idea...
@scovel, I think is probably another case of the container can do it but the registration method is missing for non generic.
I can add it but I may not be able to get to it till this weekend because of family obligations.
Sounds good. I finished up the rest of the port and didn't find anything else I need. Let me know when you want me to test.
Have a good weekend.
Ok I've pushed out a beta to nuget with the new ImportProperty method.
The beta is working great! Thanks for your efforts again.
Very cool, in 2-3 weeks I’ll plan to do an official release.
How's it going with the official release? We have a release coming up in a week or so and I'd like to change my Grace package from Beta before that happens.
Thanks,
Sean
I’ll do an official release this weekend.
marking as closed in release 6.4.2
I'm trying to port some code from Unity. (SolrNet container integration)
Here's the syntax..
Another:
The point seems to be to create a named (keyed?) registrations.
You get this instances like this:
How would you do this in Grace?