Try our conversational search powered by Generative AI!

StructureMap problem

Vote:
 

Hi, I am having problems with structuremap again.

In Global.asax, I have an override of RegisterRoutes:

protected override void RegisterRoutes(RouteCollection routes)
        {
            base.RegisterRoutes(routes);
            ObjectFactory.BuildUp(this); // with or without this line, the next line breaks

            var contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>(); // breaks here
            ....
        }

    

I have a configurable module, that gets called first (before RegisterRoutes):

    [ModuleDependency(typeof(ServiceContainerInitialization))]
    [InitializableModule]
    public class DependencyResolverInitialization : IConfigurableModule
    {
        public void ConfigureContainer(ServiceConfigurationContext context)
        {
            IContainer container = IoC.Initialize();
            DependencyResolver.SetResolver(new StructureMapDependencyResolver(container));
            GlobalConfiguration.Configuration.DependencyResolver = new StructureMapDependencyResolver(container);

            ObjectFactory.BuildUp(this);
        }
...

   I have referenced StructureMap from this location:

D:\...\trunk\src\Project.Web\packages\structuremap.2.6.4.1\lib\net40\StructureMap.dll

Now, in web.config, I am having this commented out:

      <!--<dependentAssembly>
        <assemblyIdentity name="StructureMap" publicKeyToken="e60ad81abae3c223" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.6.4.0" newVersion="2.6.4.0" />
      </dependentAssembly>-->

When I use ObjectFactory.WhatDoIHave();, I get the following error:

The type 'StructureMap.ObjectFactory' exists in both 'StructureMap.dll' and 'StructureMap.dll'

If I uncomment the web.config part, I get:

Missing requested Instance property "NamedIndexingService" for InstanceKey "6b1c69a3-1eba-470c-95fb-492045313561"

For the version with commented out dependentAssembly in web.config, I can comment out the problematic part of code, run the app, uncomment it and it works. I would really like a real solution instead of this tweak.

Any clues on what I'm doing wrong?

 

 

#72288
Jun 12, 2013 14:54
Vote:
 

Hi Marija!

We need the versionredirect in order for the EPiServer core to load the correct version. Potentially you can try redirecting to a newer version given that it's backwards compatible with the old version. Removing the redirect will otherwise give you two different versions loaded in the same app domain which usually means trouble.

#72294
Jun 12, 2013 16:47
Vote:
 

Hi, thx, but in that case I get:

Missing requested Instance property "NamedIndexingService" for InstanceKey "1c0b201e-8c75-49d0-90ce-2c9c25305f2a"

 
#72314
Edited, Jun 13, 2013 9:37
Vote:
 

I have figured out that the line EndsWith("Service") makes the problem with NamedIndexingService.

ObjectFactory.Configure(x =>
                {
                    x.Scan(s =>
                        {
                            s.Assembly("Mogul.Web.Framework");
                            s.Assembly("PROJECT.Web");
                            s.WithDefaultConventions();
                        });


                    ...
                    x.SetAllProperties(
                        policy => policy.NameMatches(name => name.EndsWith("Service")));
                    ...
                });

Without it, the exception doesn't occur.

I have removed it, since it is a part of a default convension and in the module public class ContentInitializableModule : IInitializableModule that subscibes to content events, I am manually getting the instance of my service class in public void Initialize(InitializationEngine context):

_contentService = ObjectFactory.GetInstance<IContentService>();

#72338
Edited, Jun 13, 2013 12:38
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.