November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
One trick would be to decorate `EPiServer.DataAbstraction.CategoryRepository` class in StructureMap, intercept method invocations and call something that you need then.
Not sure (can't remember) if you can decorate abstract class. If that's not an option in structure map (which sounds logical from OOP perspective) that option maybe would be to create an interceptor around it.
Agree that category repo should be hidden behind interface and operations should provide "hookable" events tho..
I managed to accomplish this requirement with the decorator, I couldn't use interceptor because only virtual members of the class can be intercepted.
abstract class CategoryRepositoryDecorator : CategoryRepository { private readonly CategoryRepository _inner; public CategoryRepositoryDecorator(CategoryRepository inner) { _inner = inner; } public override void Save(Category category) { _inner?.Save(category); } public override void Delete(Category category) { _inner?.Delete(category); } public override Category GetRoot() { return _inner?.GetRoot(); } public override Category Get(int id) { return _inner?.Get(id); } public override Category Get(string name) { return _inner?.Get(name); } }
class DecoratedCategoryRepository : CategoryRepositoryDecorator { public DecoratedCategoryRepository(CategoryRepository inner) : base(inner) { } public override void Save(Category category) { base.Save(category); Debug.WriteLine("Overriden category save method triggered!"); } public override void Delete(Category category) { base.Delete(category); Debug.WriteLine("Overriden delete category method triggered!"); } }
private static void ConfigureContainer(ConfigurationExpression container) { container.For<CategoryRepository>().DecorateAllWith<DecoratedCategoryRepository>(); }
Thanks
This sounds like great sccess! ;)
Nothing, just 2 my cents, usually I name decorated object as "_inner". For me at least makes sense when reading code - this is something being wrapped.
Looks like this was added in the latest update (update 206) with the new interface ICategoryEvents
https://world.episerver.com/releases/episerver---update-206/
Version 11.5.0 added events for categories, see https://world.episerver.com/documentation/Release-Notes/?versionFilter=11.5.0&packageFilter=EPiServer.CMS.Core&typeFilter=All
Hello,
I'm wondering can we listen to any events for categories? More specifically, I need to do some action when a content editor adds a new category.
If this functionality is not available yet, it should be proposed as a new feature
Any other opinion how to solve this requirement?
Thanks