Solrnet, Unity and manual mapping

113 views
Skip to first unread message

Markus Engelhardt

unread,
Dec 5, 2013, 3:02:47 AM12/5/13
to sol...@googlegroups.com
Hi there.

After the problems I had with registering my own MappingManager by using the Microsoft ServiceLocator,
bvut I wanted to switch my design to Unity anyway as this is usually used for IoC at our place.

So currently I am doing fine, but when I looked at the code of UnityIntegration.Solrnet and the tests in UnityMultiCoreFixture.cs
I got the impression, that if using multi cores with Solrnet and Unity, 
the preset of IReadOnlyMappingManager is automatically set to an instance of AttributesMappingManager.

As I still need to use manual mapping and thus need to inject my own mapping manager here,
I thought of creating a method for setting up one SolrServerElement with one container and the MappingManager
with a signature like this:

 public IUnityContainer ConfigureContainer(SolrServerElement solrServer, IUnityContainer container, IReadOnlyMappingManager mappingManager) 

And of course each SolrServerElement would need his own UnityContainer then, not one for all as the design now suggests.
(if I get all of this right...)

Would this be an acceptable way or should I reconfigure the containers with my MappingManagers after getting them configured
with  AttributesMappingManager first? If the 2nd would be preferrable, could you point out how you would do this?

Sorry for all of these questions...

Thank you, 

Markus

Markus Engelhardt

unread,
Dec 5, 2013, 3:15:15 AM12/5/13
to sol...@googlegroups.com
On the 2nd thought, it appears to me, that it probably would be the better idea to 
make 

        IReadOnlyMappingManager

generic too like
        IReadOnlyMappingManager<Entity>

Would it require to make more classes generic?
Of course I am aware that by doing this, I'd have to refactor all of Solrnet,
so I am not really keen on making such a big change...      

But then I could register the MappingManagers in one UnityContainer like all the rest...
Am I correct?
Or are there more easy ways I am too blind to see?

Markus Engelhardt

unread,
Dec 12, 2013, 6:27:04 AM12/12/13
to sol...@googlegroups.com
So I think I live withe workaround that I update the 

     IReadOnlyMappingManager

manually after initialising the UnityContainer. Then I keep an collection of my own where I store the instances
of UnityContainer and SolrServerElement for each document type.

The code now looks like this:

            IReadOnlyMappingManager mapper     = this.InitializeMappingManager(schema);
            IUnityContainer  container                     = new UnityContainer();
            SolrServerElement solrServerElement  = SolrServices.Instance.GetBy(typeof(T));

            SolrServers servers = new SolrServers();
            servers.Add(solrServerElement);
            container = new SolrNetContainerConfiguration().ConfigureContainer(servers, container);

            container.RegisterType<IReadOnlyMappingManager, MemoizingMappingManager>(new InjectionConstructor(mapper));

            // and then I store all in my dictionary

Kalpana Sivanandan

unread,
Feb 14, 2016, 3:01:47 PM2/14/16
to SolrNet
Hello

I am trying to implement SolrNet with Unity

I am not sure what the necessary steps are:

So far this is what I have in my Unityconfig.cs

private static Lazy<IUnityContainer> container = new Lazy<IUnityContainer>(() =>

        {

            var container = new UnityContainer();

            RegisterTypes(container);

            return container;

        });

 

        

        public static IUnityContainer GetConfiguredContainer()

        {

            return container.Value;

}

public static void RegisterTypes(IUnityContainer container)

        {

            

            container.RegisterType<INewsReader, NewsReader>();

            

            

        }


Any help is greatly appreciated


Thanks

Reply all
Reply to author
Forward
0 new messages