Skip to content

Instantly share code, notes, and snippets.

View straubt1's full-sized avatar
💭
Terraform All The Things

Tom Straub straubt1

💭
Terraform All The Things
View GitHub Profile
@straubt1
straubt1 / ExceptionAspect.cs
Created August 21, 2015 12:33
AOPinIoC_ExceptionAspect
public class ExceptionAspect : Aspect
{
public override void ProcessInvocation(IInvocation invocation)
{
try
{
invocation.Proceed();
}
catch (Exception exception)
{
@straubt1
straubt1 / Aspect.cs
Created August 21, 2015 12:32
AOPinIoC_Aspect
/// <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();
@straubt1
straubt1 / ProjectDataLocal_GetAllItems.cs
Created August 21, 2015 12:32
AOPinIoC_ProjectDataLoca_GetAllItems
public List<ProjectItem> GetAllItems()
{
var start = DateTime.Now;
try
{
return _masterList;
}
catch (Exception exception)
{
LogException(exception);
@straubt1
straubt1 / ProjectDataLocal.cs
Created August 21, 2015 12:28
AOPinIoC_ProjectDataLocal
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" },
@straubt1
straubt1 / DataInstaller.cs
Created August 21, 2015 12:25
AOPinIoC_DataInstaller
public class DataInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(Component.For<IProjectData>()
.ImplementedBy<ProjectDataLocal>());
}
}
@straubt1
straubt1 / Program.cs
Last active August 29, 2015 14:27
AOPinIoC_Program
class Program
{
private static WindsorContainer _kernel;
static void Main(string[] args)
{
_kernel = new WindsorContainer();
_kernel.Install(FromAssembly.This());
var pData = _kernel.Resolve<IProjectData>();