SiteDefinition.Current.SiteUrl returns null in AfterInstall()

Vote:
 

We are trying to acces `SiteDefinition.Current` at the time of `AfterInstall`. What we need is `SiteUrl` and `Id` but it seems that at the time of this event they are not available.

How can we postpone the calling of `AfterInstall` or otherwise, could we attach an event listener in `AfterInstall` that can later in the pipeline provide us the data?

Update:

From what I can see in the documentation and from here (enumerating the order of the execution of dependencies), decorating the class like the following should have EPiServer.Web initialized, and  by extent, SiteDefinition.Current.

[InitializableModule]
[ModuleDependency(typeof(Web.InitializationModule))]
public class ModulePackageInitializer : PackageInitializer

Decorated the class like bellow with no results.

[InitializableModule]
[ModuleDependency(typeof(EPiServer.Packaging.PackageInitializer))]
public class ModulePackageInitializer : PackageInitializer
#181045
Aug 07, 2017 15:27
Vote:
 

Not sure, it will solve your problem documentation says you should add dependency on  PackagingInitialization (Derived class should be marked with ModuleDependencyAttribute with dependency on PackagingInitialization.))

#181055
Aug 07, 2017 23:27
Vote:
 

Hi Tahir,

We have tried that as well. Same result. unfortunately.

#181069
Aug 08, 2017 9:38
Vote:
 

Just another pointer, Are you aware of "TerminateInitializationException"? 

Check this link as well

https://world.episerver.com/blogs/Magnus-Strale/Dates/2009/12/The-new-initialization-system---How-to-write-an-initialization-module-and-advanced-topics/

#181074
Aug 08, 2017 10:05
Vote:
 

No I was not aware. How can it be used?

Like this?

if (SiteDefinition.Current.SiteUrl == null)
{
            throw new TerminateInitializationException();
}



#181077
Aug 08, 2017 10:47
Vote:
 

Effectively yes. See the URL that I pasted in last post. He is doing the same thing as you are...

#181080
Aug 08, 2017 12:05
Vote:
 

I have seen it, but am not aware of the methods he is calling>

 var section = EPiServerFrameworkSection.Instance; 
         InitializeFromConfig(section.SiteHostMapping); 
         var configSiteId = SiteIdFromConfig(section); // Get info from config file / 

         var actualSiteId = SiteIdFromRequest();   

"InitializeFromConfig", "SiteIdFromConfig" and "SiteIdFromRequest"

#181081
Edited, Aug 08, 2017 13:01
Vote:
 
<p>Solved with this</p> <pre class="cs hljs" contenteditable="false"><span>var</span> siteDefinitionRepository = ServiceLocator.Current.GetInstance&lt;SiteDefinitionRepository&gt;(); <span>var</span> siteDefinitions = siteDefinitionRepository.List().ToList();</pre>
#181084
Aug 08, 2017 13:55
Vote:
 

You should use the interface instead

var siteDefinitionRepository = ServiceLocator.Current.GetInstance<ISiteDefinitionRepository>();
var siteDefinitions = siteDefinitionRepository.List().ToList();
#198412
Oct 26, 2018 14:29
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.