我试图在这个答案中实现该解决方案,以便能够限制WeBlog中标记云中显示的标记数量。此外,我正在使用文档中的这些指示。
我修改了WeBlog配置以指向我自己的自定义TagManager实现。
<setting name="WeBlog.Implementation.TagManager" value="My.Namespace.CustomTagManager"/>如果我加载sitecore/admin/showconfig.aspx,我可以确认配置设置已经用新值进行了更新。
我的CustomTagManager目前是ITagManager接口的基本实现。
public class CustomTagManager : ITagManager
{
public string[] GetTagsByBlog(ID blogId)
{
throw new System.NotImplementedException();
}
public string[] GetTagsByBlog(Item blogItem)
{
throw new System.NotImplementedException();
}
public Dictionary<string, int> GetTagsByEntry(EntryItem entry)
{
throw new System.NotImplementedException();
}
public Dictionary<string, int> GetAllTags()
{
throw new System.NotImplementedException();
}
public Dictionary<string, int> GetAllTags(BlogHomeItem blog)
{
throw new System.NotImplementedException();
}
public Dictionary<string, int> SortByWeight(IEnumerable<string> tags)
{
throw new System.NotImplementedException();
}
}我可以反映已部署的DLL,并看到这些更改是一定要做的,但是这些更改没有影响。没有抛出任何异常,标记云继续填充,就好像我根本没有做任何更改一样。这就像配置文件的更改被完全忽略了一样。
为了编写我自己的客户TagManager类,我还需要更改什么?
我使用的是WeBlog 5.2和Sitecore 7.1。
发布于 2016-03-03 11:01:48
在查看了WeBlog代码之后,很明显,fallback对象被使用了,而我的配置更改被忽略了。
造成这种情况的原因是WeBlog做了:
var type = Type.GetType(typeName, false);GetType方法仅在mscorlib.dll或当前程序集中找到类型时才能工作。因此,修复只需提供程序集完全限定的名称即可。
<setting name="WeBlog.Implementation.TagManager" value="My.Assembly.CustomTagManager, My.Assembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>这是WeBlog代码:
private static T CreateInstance<T>(string typeName, Func<T> fallbackCreation) where T : class
{
var type = Type.GetType(typeName, false);
T instance = null;
if (type != null)
{
try
{
instance = (T)Sitecore.Reflection.ReflectionUtil.CreateObject(type);
}
catch(Exception ex)
{
Log.Error("Failed to create instance of type '{0}' as type '{1}'".FormatWith(type.FullName, typeof(T).FullName), ex, typeof(ManagerFactory));
}
}
if(instance == null)
instance = fallbackCreation();
return instance;
}https://stackoverflow.com/questions/35768887
复制相似问题