0

I am migrating my project from Spring.Net to Simple Injector. In Spring.Net, there is a concept of having several functions nested under a single transaction using transaction decorator. The functionality of the Transaction decorator was to Rollback the transactions (including the DB inserts/updated) on Error across nested functions / service functions which would have a DB call individually.

Is there any equivalent in Simple Injector?

Sample Code of Spring.NET below

User Service

  [Transaction(TransactionPropagation.Required)]
    public bool RegisterUser(UserModel)
    {
    //Insert User DB Call
    int result = _Userrepository.UserInsert(UserModel);
    _subscriberservice.InsertSubscriber(UserModel);

}

Subscriber Service

    public bool InsertSubscriber(UserModel);
    {
    //Insert Subscriber DB Call
    int result = _subscriberrepository.SubscriberInsert(UserModel);

}

If the Insert Subscriber Service Insert fails, the User Insert also has to Roll back

Algi
  • 195
  • 1
  • 2
  • 11

1 Answers1

0

The preferred method of doing this using Simple Injector, is to apply Decorators around your classes, as explained here.

Spring.NET, however, uses a different approach, called dynamic interception. It generates Decorators for you on the fly at runtime that will be injected with interceptor classes you created.

Simple Injector has no built-in support for dynamic interception, but this can be added, as explained here. This Stack Overflow answer describes how to integrate Simple Injector with Castle Dynamic Proxy, which is the framework Spring.NET uses under the covers as well.

Steven
  • 166,672
  • 24
  • 332
  • 435