-
Notifications
You must be signed in to change notification settings - Fork 218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do I have to have a Mvc.sitemap or can I drive SiteMapPathHelper using Attributes only ? #197
Comments
In theory it should work, but it is not something I have tested. However in order to make it work you need to:
// Original DI configuration
var builder = this.For<ISiteMapBuilder>().Use<CompositeSiteMapBuilder>()
.EnumerableOf<ISiteMapBuilder>().Contains(y =>
{
y.Type<XmlSiteMapBuilder>()
.Ctor<ISiteMapXmlReservedAttributeNameProvider>().Is(reservedAttributeNameProvider)
.Ctor<IXmlSource>().Is(xmlSource);
y.Type<ReflectionSiteMapBuilder>()
.Ctor<IEnumerable<string>>("includeAssemblies").Is(includeAssembliesForScan)
.Ctor<IEnumerable<string>>("excludeAssemblies").Is(new string[0]);
y.Type<VisitingSiteMapBuilder>();
});
// New DI Configuration
var builder = this.For<ISiteMapBuilder>().Use<CompositeSiteMapBuilder>()
.EnumerableOf<ISiteMapBuilder>().Contains(y =>
{
y.Type<ReflectionSiteMapBuilder>()
.Ctor<IEnumerable<string>>("includeAssemblies").Is(includeAssembliesForScan)
.Ctor<IEnumerable<string>>("excludeAssemblies").Is(new string[0]);
y.Type<VisitingSiteMapBuilder>();
}); I am showing you the StructureMap configuration, but you should be able to work this out with your preferred DI container. Basically you need to do this to ensure the root node is set by the ReflectionSiteMapBuilder rather than the XmlSiteMapBuilder and also so your setup won't be looking for a .sitemap file. Give it a try and let me know if there are any problems - if this configuration is not supported currently, it definitely is something that should be. It might help if you try it in a demo project first before doing it in your real project. That way if there are bugs you can just post your demo project on GitHub so we can analyze what is going on with your exact configuration. |
FYI - I did a quick test and it seems to work fine when set up the way I describe it above. I did have to add a few steps to make it complete:
All DI configuration is done in Here is the demo project I created: https://github.com/NightOwl888/MvcSiteMapProvider_197. I commented the lines I removed so you can more easily see what changed from the default configuration. I started by using the default MVC internet template and installing the |
Thanks so much – I didn’t expect such a quick response; worked a treat. I happen to be using structuremap so your example was really easy to follow. All the best John Kattenhorn From: NightOwl888 [mailto:[email protected]] FYI - I did a quick test and it seems to work fine when set up the way I describe it above. I did have to add a few steps to make it complete:
All DI configuration is done in DI\StructureMap\Registries\MvcSiteMapProviderRegistry.cs. Here is the demo project I created: https://github.com/NightOwl888/MvcSiteMapProvider_197. I commented the lines I removed so you can more easily see what changed from the default configuration. I started by using the default MVC internet template and installing the MvcSiteMapProvider.MVC4.DI.StructureMap package only. — |
I'd like to use the SiteMapPathHelper by decorating the Controller Actions Only, but I don't seem to make it work correctly and it loses the 'root' node.
On HomeController I have
public class HomeController : Controller
{
On dashboard I have
public class DashboardController : Controller
{
//
// GET: /Dashboard/
[MvcSiteMapNode(Title = "Dashboard", Key = "Dashboard", ParentKey = "Home")]
public ActionResult Index()
{
return View();
}
If I set a breakpoint inside SiteMapPathHelperModel the Model seems to be empty, I can make it work by added nodes to the sitemap file but that's not the way I want to do; any ideas ?
Thanks
John
The text was updated successfully, but these errors were encountered: