This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Program | |
{ | |
private static WindsorContainer _kernel; | |
static void Main(string[] args) | |
{ | |
_kernel = new WindsorContainer(); | |
_kernel.Install(FromAssembly.This()); | |
var pData = _kernel.Resolve<IProjectData>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DataInstaller : IWindsorInstaller | |
{ | |
public void Install(IWindsorContainer container, IConfigurationStore store) | |
{ | |
container.Register(Component.For<IProjectData>() | |
.ImplementedBy<ProjectDataLocal>()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ProjectDataLocal : IProjectData | |
{ | |
private List<ProjectItem> _masterList; | |
public ProjectDataLocal() | |
{ | |
_masterList = new List<ProjectItem> | |
{ | |
new ProjectItem { Id = Guid.Parse("5843b73d-45f7-4284-86cf-c2f07821e01d"), Name ="Item 1", ItemType = "A" }, | |
new ProjectItem { Id = Guid.Parse("9815b73d-45f7-4284-86cf-c2f07821e01d"), Name ="Item 2", ItemType = "A" }, | |
new ProjectItem { Id = Guid.Parse("2100b73d-45f7-4284-86cf-c2f07821e01d"), Name ="Item 3", ItemType = "B" }, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public List<ProjectItem> GetAllItems() | |
{ | |
var start = DateTime.Now; | |
try | |
{ | |
return _masterList; | |
} | |
catch (Exception exception) | |
{ | |
LogException(exception); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Abstract class to wrap Castle Windsor's IInterceptor to only fire if the method or class is decorated with this attribute. | |
/// </summary> | |
public abstract class Aspect : Attribute, IInterceptor | |
{ | |
public void Intercept(IInvocation invocation) | |
{ | |
if (!CanIntercept(invocation, GetType())) | |
{//method is NOT decorated with the proper aspect, continue as normal | |
invocation.Proceed(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ExceptionAspect : Aspect | |
{ | |
public override void ProcessInvocation(IInvocation invocation) | |
{ | |
try | |
{ | |
invocation.Proceed(); | |
} | |
catch (Exception exception) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TimingAspect : Aspect | |
{ | |
public override void ProcessInvocation(IInvocation invocation) | |
{ | |
var sw = Stopwatch.StartNew(); | |
invocation.Proceed(); | |
sw.Stop(); | |
Console.WriteLine("({0})Elapsed: {1}", invocation.MethodInvocationTarget.Name, sw.Elapsed); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DataInstaller : IWindsorInstaller | |
{ | |
public void Install(IWindsorContainer container, IConfigurationStore store) | |
{ | |
container.Register(Component.For<ExceptionAspect>()); | |
container.Register(Component.For<TimingAspect>()); | |
container.Register(Component.For<IProjectData>() | |
.ImplementedBy<ProjectDataLocal>() | |
.Interceptors( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ExceptionAspect] | |
[TimingAspect] | |
public List<ProjectItem> GetAllItems() | |
{ | |
return _masterList; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DataInstaller : IWindsorInstaller | |
{ | |
public void Install(IWindsorContainer container, IConfigurationStore store) | |
{ | |
var isProd = ConfigurationManager.AppSettings["IsProduction"] == "True"; | |
container.Register(Component.For<ExceptionAspect>()); | |
container.Register(Component.For<TimingAspect>()); | |
var iProjData = Component.For<IProjectData>().ImplementedBy<ProjectDataLocal>(); | |
iProjData.Interceptors(typeof(ExceptionAspect)); |
OlderNewer