Skip to content

Commit

Permalink
Merge branch 'master' of github.com:pamidur/aspect-injector
Browse files Browse the repository at this point in the history
  • Loading branch information
pamidur committed Jan 24, 2022
2 parents 9808b6f + 40f8321 commit 367f138
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/errors/AI_A000.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# AI_A000 - Aspect should contain effect
---
This warning occures when there is an aspect class that does nothing - does not contain any effect.
```c#
[Aspect(Scope.Global)]
public class MyAspect
{

}
```

Consider adding an [Advice](../advice.md) or a [Mixin](../mixin.md) to your aspect.
16 changes: 16 additions & 0 deletions docs/errors/AI_A001.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# AI_A001 - Aspect must have valid signature
---
This error occurs when the aspect class signature does not conform with the following rules:
- Aspect must not be generic
- Aspect must not be abstract
- Aspect must not be static
- Aspect must be public

Example of valid aspect class definition:
```c#
[Aspect(Scope.Global)]
public class MyAspect
{
//advices
}
```
21 changes: 21 additions & 0 deletions docs/errors/AI_A002.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# AI_A002 - Aspect factory must contain factory method
---
This error occurs when the aspect class uses Factory but Factory class does not have proper factory method.

Example of valid aspect class definition and factory class definition:
```c#
[Aspect(Scope.Global, Factory = typeof(MyFactory))]
public class MyAspect
{
//advices
}

public class MyFactory
{
public static object GetInstance(Type type)
{
// return aspect instance
}
}

```
25 changes: 25 additions & 0 deletions docs/errors/AI_A003.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# AI_A003 - Aspect must have public parameterless constructor or factory
---
This error occurs when the aspect class does not have parameterless constructor nand defined factory.
Aspect class instances need a way to be instantinated. So they should either have parameterless constructor:
```c#
[Aspect(Scope.Global)]
public class MyAspect
{
public MyAspect()
{
}
//advices
}
```
... or factory:
```c#
[Aspect(Scope.Global, Factory = typeof(MyFactory))]
public class MyAspect
{
public MyAspect(ILogger logger)
{
}
//advices
}
```
67 changes: 67 additions & 0 deletions docs/mixin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
## Aspect Injector Docs

- [<- to contents...](readme.md)

### <a name="this"></a>Mixins

**Mixins** is a powerfull feature that enables developers to add new logic/properties to an object by automatically implementing interfaces.
Aspect containing a mixin will create members in target similar to interface's and proxy them back to the aspect.

Consider scnerio where you want to add a property to a target:
```c#
public class Target
{
public void Do() {}
}
```

For this you need to create an interface that describes features you want to add:
```c#
public interface IHaveProperty
{
string Data { get; set; }
}
```

then we will create an aspect:
```c#
[Aspect(Scope.Global)]
[Injection(typeof(MyAspect))]
[Mixin(typeof(IHaveProperty))]
public class MyAspect: Attribute, IHaveProperty
{
public string Data { get; set; }
}
```

And finally if apply this new aspect-attribute to `Target` will make look like (after compilation):
```c#
[MyAspect]
public class Target : IHaveProperty
{
string IHaveProperty.Data
{
get
{
return ((IHaveProperty)My1Aspect.__a$_instance).Data;
}
set
{
((IHaveProperty)My1Aspect.__a$_instance).Data = value;
}
}

public void Do()
{
}
}
```

Note that it isn't necessary to apply aspect to `Target` class itself, it is enough to apply it any member, like this:
```c#
public class Target
{
[MyAspect]
public void Do() {}
}
```

0 comments on commit 367f138

Please sign in to comment.