Any Free Alternative to PostSharp [closed]

2019-04-22 00:46发布

The application we are building sends out different kind of emails regularly. I stored the email templates in an Azure blob storage and the methods responsible for sending emails pull the appropriate email templates from there. I want the templates to be outside of the hosted service in case I want to update it, I can do that simply by uploading new templates to the blob.

The problem I'm having, from performance and cost perspective, is that the email templates rarely change within a 24hr period. So caching the method in a way akin to [OutputCache(Duration = duration, VaryByParam = "id")] in ASP.NET MVC will be an ideal solution in order to increase the worker role performance. How to do this is now a problem. I learnt of PostSharp but our budget didn't take PostSharp's licencing fee into consideration from the beginning!

Any other free alternatives? Thanks for helping out.

6条回答
地球回转人心会变
2楼-- · 2019-04-22 01:23

If you just want AOP functionality, you can use something like Ninject Interception.

http://codepyre.com/2010/03/using-ninject-extensions-interception-part-1-the-basics/

查看更多
We Are One
3楼-- · 2019-04-22 01:26

I've used SNAP a few times. It's free and very easy to setup and use with a number of IoC containers

查看更多
The star\"
4楼-- · 2019-04-22 01:32

PostSharp Starter Edition is free and would meet your requirements.

查看更多
贪生不怕死
5楼-- · 2019-04-22 01:34

Have you considered using local storage resources to pull the templates out of storage? You could configure an interval in the Run method of the RoleEntryPoint.

[Update]

I might not have been clear above. The template should be stored in Blob Storage. Local Storage would be used to cache a copy of the template locally on each instance of the service. If you store the ETag in a separate file this will allow you to verify the template has changed before transferring the blob i.e.:

  • welcome.tpl
  • welcome.tag.tpl

In the RoleEntryPoint, read the etag from the *.tag.tpl file. Submitting your request against blob storage with a conditional headers passing the Etag with an If-None-Match access condition. If the blob hasn't been updated it will return an HTTP 304 Not Modified response code, if it was updated, the blob will be downloaded.

[/Update]

查看更多
你好瞎i
6楼-- · 2019-04-22 01:39

I have implemented method level caching in the past, using the following combination:

  1. Autofac as IoC container
  2. Autofac's MVC3 integration package
  3. Autofac's DynamicProxy2 (castle) integration for interception support
  4. Custom Attribute to decorate classes that require caching support
  5. Custom Interceptor to add method level caching

The custom attribute and interceptor is quite easy to set up. The main problem with method level caching is, I believe, how you determine cache hits and misses in an optimal, yet precise way.

In my case it needed to be generic (support any type of method call and parameters), so I had to create a flexible way to hash all method parameter values in order to distinguish one call from another. But in your case, this could actually be a very specific interceptor, that already knows the structure of your method call, which would make things a lot easier.

Now about the actual caching, you can take advantage of .NET's caching support, available in the System.Runtime.Caching namespace, which already provides a MemoryCache if that's suitable for you.

查看更多
混吃等死
7楼-- · 2019-04-22 01:41

You can try to use KingAOP - easy for such tasks. The main difference is:
1) generating code in runtime without wasting additional compile time.
2) based on "dynamic" - it's mean that your code will generated via official C# compiler.

It's open source project: https://github.com/AntyaDev/KingAOP

Take a look for article:
http://www.codeproject.com/Tips/624586/Introducing-the-KingAOP-Framework-Part-1

查看更多
登录 后发表回答