I being following the Unity Interception link, to implement Unity in my project.
By, following a link I have made a class as shown below:
[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;
}
}
Till now I have done nothing special, just followed the example as explained in the upper link. But, when I have to implement the Unity Interception class, I came up with lots of confusion.
Suppose, I have to implement on one of the methods in my class like:
[MyInterception]
public Model GetModelByID(Int32 ModelID)
{
return _business.GetModelByID(ModelID);
}
This is the main thing where I have being stuck, I dnt know how I have to use the Intercept class over the GetModelByID() method and how to get the unity.
Please help me, and please also explain the concept of Unity Interception.