プロジェクトに Unity を実装するために、 Unity Interceptionリンクをたどっています。
リンクに従って、以下に示すようにクラスを作成しました。
[AttributeUsage(AttributeTargets.Method)]
public class MyInterceptionAttribute : Attribute
{
}
public class MyLoggingCallHandler : ICallHandler
{
IMethodReturn ICallHandler.Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
IMethodReturn result = getNext()(input, getNext);
return result;
}
int ICallHandler.Order { get; set; }
}
public class AssemblyQualifiedTypeNameConverter : ConfigurationConverterBase
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
{
if (value != null)
{
Type typeValue = value as Type;
if (typeValue == null)
{
throw new ArgumentException("Cannot convert type", typeof(Type).Name);
}
if (typeValue != null) return (typeValue).AssemblyQualifiedName;
}
return null;
}
public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
{
string stringValue = (string)value;
if (!string.IsNullOrEmpty(stringValue))
{
Type result = Type.GetType(stringValue, false);
if (result == null)
{
throw new ArgumentException("Invalid type", "value");
}
return result;
}
return null;
}
}
これまで、私は特別なことは何もしていません。上のリンクで説明されている例に従っているだけです。しかし、Unity Interception クラスを実装する必要があるとき、多くの混乱が生じました。
次のようなクラスのメソッドの 1 つに実装する必要があるとします。
[MyInterception]
public Model GetModelByID(Int32 ModelID)
{
return _business.GetModelByID(ModelID);
}
これは私が立ち往生している主なものです。GetModelByID ()メソッドで Intercept クラスを使用する方法と、ユニティを取得する方法がわかりません。
助けてください。また、Unity Interception の概念についても説明してください。