-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:pamidur/aspect-injector
- Loading branch information
Showing
5 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
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
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. |
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
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 | ||
} | ||
``` |
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
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 | ||
} | ||
} | ||
|
||
``` |
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
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 | ||
} | ||
``` |
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
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() {} | ||
} | ||
``` |