Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sagifogel/ncop
Composite-aspect oriented framework for .NET
https://github.com/sagifogel/ncop
aop aspect aspect-oriented-framework aspect-oriented-programming composite csharp mixins
Last synced: about 1 month ago
JSON representation
Composite-aspect oriented framework for .NET
- Host: GitHub
- URL: https://github.com/sagifogel/ncop
- Owner: sagifogel
- License: mit
- Created: 2012-10-07T14:29:08.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2022-06-14T18:28:15.000Z (over 2 years ago)
- Last Synced: 2024-11-17T00:25:50.166Z (about 2 months ago)
- Topics: aop, aspect, aspect-oriented-framework, aspect-oriented-programming, composite, csharp, mixins
- Language: C#
- Homepage:
- Size: 3.56 MB
- Stars: 29
- Watchers: 5
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: license
Awesome Lists containing this project
README
NCop
===================
What is **NCop**?**NCop** is a framework that implements Composite/Aspect Oriented Programming that encapsulates the concepts of [Mixins](https://github.com/sagifogel/NCop/blob/master/README.md#mixins), [Aspects](https://github.com/sagifogel/NCop/blob/master/README.md#aspects) and [Dependency Injection](https://github.com/sagifogel/NCop/blob/master/README.md#dependency-injection), using the standard .NET.
The main purpose of composites is separation of concerns. You achieve it by defining different roles within different entities and combine all of them using **NCop** (much like multiple inheritance).### Installing
```
Install-Package NCop
```Please visit the [Wiki](https://github.com/sagifogel/NCop/wiki) page for explanations and demos.
------------A mixin is an interface with implemented methods.
Mixins exists in .NET in the form of object oriented interfaces implementation.```csharp
public interface IDeveloper
{
void Code();
}
``````csharp
public class CSharpDeveloperMixin : IDeveloper
{
public void Code() {
Console.WriteLine("C# coding");
}
}
```### Composites
Composites are the artifacts of **NCop** processing. A composite is a combination of Mixins and Aspects.
In order to create a composite type you need to annotate one of the interfaces with a `CompositeAttribute`
and also to tell **NCop** to match between interface and implementation by annotating the composite type with a `MixinsAttribute`.```csharp
[TransientComposite]
[Mixins(typeof(CSharpDeveloperMixin))]
public interface IDeveloper
{
void Code();
}
```Aspects aims to increase modularity by allowing the separation of cross-cutting concerns.
In order to create an aspect you should first create an aspect class that will hold your desired join points.```csharp
public class StopwatchActionInterceptionAspect : ActionInterceptionAspect
{
private readonly Stopwatch stopwatch = null;public StopwatchActionInterceptionAspect() {
stopwatch = new Stopwatch();
}public override void OnInvoke(ActionInterceptionArgs args) {
stopwatch.Restart();
args.Proceed();
stopwatch.Stop();
Console.WriteLine("Elapsed Ticks: {0}", stopwatch.ElapsedTicks);
}
}
```The second thing that you will need to do is to annotate the method which you want to apply the aspect on.
```csharp
[TransientComposite]
[Mixins(typeof(CSharpDeveloperMixin))]
public interface IDeveloper
{
[MethodInterceptionAspect(typeof(StopwatchActionInterceptionAspect))]
void Code();
}
```**NCop** IoC is based on Funq - which was adopted because of its excellent performance and memory characteristics.
In order to resolve an artifact of **NCop** you need to create a composite IoC Container,
and call the `Resolve` function.```csharp
static void Main(string[] args) {
IDeveloper developer = null;
var container = new CompositeContainer();container.Configure();
developer = container.Resolve();
developer.Code();
}
```The expected output should be:
```
"C# coding"
"Elapsed Ticks: [Number of ticks]"
```