Transaction attribute not rolling back transaction

197 views
Skip to first unread message

Paul

unread,
Feb 11, 2012, 2:16:56 PM2/11/12
to S#arp Architecture
Hi,

In my MVC project, my controller instantiates a business logic class
and passes in various tasks. All of the tasks use the same database
context. I have one method called Save that has been decorated with a
SharpArchContrib.Data.NHibernate.Transaction attribute. I need to
save entities in a certain order and have them roll back if anything
throws an exception. Here is the sample code below:

[Transaction]
public void Save(item1, item2)
{
try
{
item1Tasks.CreateOrUpdateItem1(item1);
item2Tasks.CreateOrUpdateItem2(item2);
}
catch (Exception ex)
{
throw ex;
}
}

In the CreateOrUpdateItem2 method I've have it purposely throwing an
exception to make sure that the database is not being updated.
However, item1 is being saved in the database when it should not be.
Here is the code for my item1 and item2 tasks respectively:

public class Item1Tasks : IItem1Tasks
{
private readonly INHibernateRepository<Item1> item1Repository;

public Item1Tasks(INHibernateRepository<Item1>
item1Repository)
{
this.item1Repository= item1Repository;
}

public Item1 CreateOrUpdateItem1(Item1 item1)
{
Item1 item1ToReturn = null;

try
{
item1ToReturn = item1Repository.SaveOrUpdate(item1);
}
catch (Exception ex)
{
throw ex;
}

return item1ToReturn;
}
}

public class Item1Tasks : IItem2Tasks
{
private readonly INHibernateRepository<Item2> item2Repository;

public Item2Tasks(INHibernateRepository<Item2>
item2Repository)
{
this.item2Repository= item2Repository;
}

public Item2 CreateOrUpdateItem2(Item2 item2)
{
Item2 item2ToReturn = null;

try
{
throw new Exception("Test");
item2ToReturn = item2Repository.SaveOrUpdate(item2);
}
catch (Exception ex)
{
throw ex;
}

return item2ToReturn;
}
}

I feel I am missing something, but I don't know what. Any help would
be greatly appreciated!

Thanks!

Seif Attar

unread,
Feb 11, 2012, 2:30:08 PM2/11/12
to sharp-arc...@googlegroups.com
Just to make sure, wherever you are creating the container, you have
called the method:

SharpArchContrib.Castle.CastleWindsor.ComponentRegistrar.AddComponentsTo(container);

Also, the Transaction attribute uses castle dynamic proxy, which
requires a method to be virtual or be an implementation of an
interface that the container is returning. (If that Save method is on
a Controller, just change add the virtual keyword to it).

This should get this working properly.

> --
> You received this message because you are subscribed to the Google Groups "S#arp Architecture" group.
> To post to this group, send email to sharp-arc...@googlegroups.com.
> To unsubscribe from this group, send email to sharp-architect...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/sharp-architecture?hl=en.
>

Paul

unread,
Feb 11, 2012, 2:48:56 PM2/11/12
to S#arp Architecture
Hi Seif,

Thanks for the reply!

I am not actually calling
SharpArchContrib.Castle.CastleWindsor.ComponentRegistrar.AddComponentsTo(container).
Currently, I am creating the container in the global.asax as such (I
took a lot from the northwind SharpArch sample):

protected virtual IWindsorContainer InitializeServiceLocator()
{
IWindsorContainer container = new WindsorContainer();
ControllerBuilder.Current.SetControllerFactory(new
WindsorControllerFactory(container));


container.RegisterControllers(typeof(HomeController).Assembly);
ComponentRegistrar.AddComponentsTo(container);

ServiceLocator.SetLocatorProvider(() => new
WindsorServiceLocator(container));

return container;
}

Here is ComponentRegistrar:

public class ComponentRegistrar
{
public static void AddComponentsTo(IWindsorContainer
container)
{
AddGenericRepositoriesTo(container);
AddCustomRepositoriesTo(container);
}

private static void AddCustomRepositoriesTo(IWindsorContainer
container)
{
container.Register(

AllTypes.Pick().FromAssemblyNamed("myproject.Infrastructure").WithService.FirstNonGenericCoreInterface(
"myproject.Domain"));

container.Register(

AllTypes.Pick().FromAssemblyNamed("myproject.Tasks").WithService.FirstNonGenericCoreInterface(
"myproject.Domain.Tasks"));
}

private static void AddGenericRepositoriesTo(IWindsorContainer
container)
{
container.AddComponent(
"entityDuplicateChecker",
typeof(IEntityDuplicateChecker), typeof(EntityDuplicateChecker));
container.AddComponent(
"sessionFactoryKeyProvider",
typeof(ISessionFactoryKeyProvider),
typeof(DefaultSessionFactoryKeyProvider));
container.AddComponent("repositoryType",
typeof(IRepository<>), typeof(NHibernateRepository<>));
container.AddComponent(
"nhibernateRepositoryType",
typeof(INHibernateRepository<>), typeof(NHibernateRepository<>));
container.AddComponent(
"repositoryWithTypedId",
typeof(IRepositoryWithTypedId<,>),
typeof(NHibernateRepositoryWithTypedId<,>));
container.AddComponent(
"nhibernateRepositoryWithTypedId",
typeof(INHibernateRepositoryWithTypedId<,>),
typeof(NHibernateRepositoryWithTypedId<,>));
}
}

What changes would I need to make based on what you suggested
regarding the call to
SharpArchContrib.Castle.CastleWindsor.ComponentRegistrar.AddComponentsTo(container)?

My save method is in the Business logic class (it does not inherit
from anything, nor implements any interfaces. It is specific to the
MVC project). Based on what you describe, then, changing it to
include virtual should be enough?

Thanks again, I do appreciate it!


On Feb 11, 2:30 pm, Seif Attar <i...@seifattar.net> wrote:
> Just to make sure, wherever you are creating the container, you have
> called the method:
>
> SharpArchContrib.Castle.CastleWindsor.ComponentRegistrar.AddComponentsTo(container);
>
> Also, the Transaction attribute uses castle dynamic proxy, which
> requires a method to be virtual or be an implementation of an
> interface that the container is returning. (If that Save method is on
> a Controller, just change add the virtual keyword to it).
>
> This should get this working properly.
>

Seif Attar

unread,
Feb 11, 2012, 3:01:58 PM2/11/12
to sharp-arc...@googlegroups.com
Change global.asax method to

protected virtual IWindsorContainer InitializeServiceLocator()
{
IWindsorContainer container = new WindsorContainer();

SharpArchContrib.Castle.CastleWindsor.ComponentRegistrar.AddComponentsTo(container);

ControllerBuilder.Current.SetControllerFactory(new
WindsorControllerFactory(container));


container.RegisterControllers(typeof(HomeController).Assembly);
ComponentRegistrar.AddComponentsTo(container);

ServiceLocator.SetLocatorProvider(() => new
WindsorServiceLocator(container));

return container;
}

and make the Save method virtual

Paul

unread,
Feb 11, 2012, 3:06:49 PM2/11/12
to S#arp Architecture
Awesome! Thanks Seif, I will give that a try!

Paul

unread,
Feb 11, 2012, 3:30:01 PM2/11/12
to S#arp Architecture
I included the line:

SharpArchContrib.Castle.CastleWindsor.ComponentRegistrar.AddComponentsTo(container);

In the method, but upon running it, it is looking for SharpArch
1.9.5. I'm using SharpArch 2.0. If I get the code from Github and
build SharpArchContrib with the new version, will I experience any
issues? Is there anything I need to look out for?

Seif Attar

unread,
Feb 11, 2012, 3:43:27 PM2/11/12
to sharp-arc...@googlegroups.com
i had already started updating, if you clone

https://github.com/seif/Sharp-Architecture-Contrib/tree/develop

and start from there.

let me know if you run into issues, better yet, a pull request :)

Paul

unread,
Feb 11, 2012, 3:54:50 PM2/11/12
to S#arp Architecture
Sure, let me do that. Before I do that, I'm not very familiar with
Github beyond downloading the files. How do I do what you described
(i.e. the clone or pull request)? Is there a wiki or something you
could direct me to?

My plan is to build just the SharpArchContrib.Castle,
SharpArchContrib.Core and the SharpArchContrib.Data and see if I can
get away with that for now :)

Thanks Seif!

On Feb 11, 3:43 pm, Seif Attar <i...@seifattar.net> wrote:
> i had already started updating, if you clone
>
> https://github.com/seif/Sharp-Architecture-Contrib/tree/develop
>
> and start from there.
>
> let me know if you run into issues, better yet, a pull request :)
>
> > To post to...
>
> read more »

Seif Attar

unread,
Feb 11, 2012, 3:58:50 PM2/11/12
to sharp-arc...@googlegroups.com
https://github.com/blog/120-new-to-git

http://help.github.com/fork-a-repo/

sorry for short replies, I am watching an online webinar :)

Paul

unread,
Feb 11, 2012, 4:02:36 PM2/11/12
to S#arp Architecture
Thanks Seif!

No problem at all! I appreciate the help!

On Feb 11, 3:58 pm, Seif Attar <i...@seifattar.net> wrote:
> https://github.com/blog/120-new-to-git
>
> http://help.github.com/fork-a-repo/
>
> sorry for short replies, I am watching an online webinar :)
>
> >> >> > > > >            Item2 item2ToReturn = null;...
>
> read more »

Seif Attar

unread,
Feb 11, 2012, 4:12:25 PM2/11/12
to sharp-arc...@googlegroups.com
Right, boring part of the webinar :)

Do you a github account? do you have git configured on your machine?
have you used any other distributed version control system before?

Paul

unread,
Feb 11, 2012, 4:17:43 PM2/11/12
to S#arp Architecture
I do not have a github account, though from what I am reading I
believe I need one. I just downloaded Git (Git-1.7.9-
preview20120201.exe) and installed in on my machine (using the
defaults). I think I will get an account next and then make an
attempt to clone the SharpArchContrib project.

I have used SVN and TFS, though not to the degree Github has been
designed for.

I need to take off at 4:40pm (EST. I'm here in Canada :) ), so I may
not respond until later tonight.

On Feb 11, 4:12 pm, Seif Attar <i...@seifattar.net> wrote:
> Right, boring part of the webinar :)
>
> Do you a github account? do you have git configured on your machine?
> have you used any other distributed version control system before?
>
> >> >> >> > > > >                item1ToReturn = item1Repository.SaveOrUpdate(item1);...
>
> read more »

Paul

unread,
Feb 11, 2012, 4:32:40 PM2/11/12
to S#arp Architecture
I tried cloning it, with the command:

git clone g...@github.com:shorttp/Sharp-Architecture-Contrib.git

However, I'm getting permission denied. Do I need to do anything on
my side, or do you need to allow me?

Thanks!
> > >> >> >> > > > > In the CreateOrUpdateItem2 method I've have it purposely throwing an...
>
> read more »

Seif Attar

unread,
Feb 11, 2012, 4:37:56 PM2/11/12
to sharp-arc...@googlegroups.com
Ok, so start with this:

http://help.github.com/win-set-up-git/

then, on https://github.com/sharparchitecture/Sharp-Architecture-Contrib

click the 'Fork' button, this will create a repository for you based
on the one from sharparchitecture team, which you have permissions to
push changes to.

on your local machine, you want to get the code from your repository:

git clone g...@github.com:YOUR_USER/Sharp-Architecture-Contrib.git

Hopefully this will work, whenit finishes, you will have the code on
the master branch on your repository. But we need to switch to
develop:

git checkout -t origin/develop

Now, you want to get my changes on your local machine.

First you add my github repository as a remote source (giving it the
name 'seif'):

git remote add seif git://github.com/seif/Sharp-Architecture-Contrib.git
git pull seif develop

Maybe I shouldn't have suggested the name seif for the repository, git
pull seif can have a funny meaning, ain't happening! :)

What happened now is that you have merged the changes from my branch
in your repository, if you push:

git push origin develop

your repository on github will have my changes on the develop branch. I think :)

Now, to get start with some work, code code code

git commit -a -m "Commit message here"
git push

And now your changes will be visible for the public, and you can do a
pull request! :)

Paul

unread,
Feb 11, 2012, 4:41:37 PM2/11/12
to S#arp Architecture
Thanks Seif, the issue was due to the public key (I need to generate
one). I need to head out, but will follow your instructions when I
get back.

Thanks!


On Feb 11, 4:37 pm, Seif Attar <i...@seifattar.net> wrote:
> Ok, so start with this:
>
> http://help.github.com/win-set-up-git/
>
> then, onhttps://github.com/sharparchitecture/Sharp-Architecture-Contrib
> >> >> >> >> > > > a Controller, just change add the virtual...
>
> read more »

Seif Attar

unread,
Feb 11, 2012, 4:42:21 PM2/11/12
to sharp-arc...@googlegroups.com
I see you have already forked from my repository, so there is no need
to pull in my changes (i.e. you can skip adding my repo as a remote
and pulling from it), you just need to clone, code code code, commit
and push

Permission denied! :S have you setup your public key properly? follow
the instructions in http://help.github.com/win-set-up-git/ for setting
stuff up.

I know it isn't as easy to get up and starting with this stuff, but
once you have it running, it kicks svn/tfs ass, massivly!

Seif Attar

unread,
Feb 11, 2012, 5:10:26 PM2/11/12
to sharp-arc...@googlegroups.com
Cool, good luck, hope that this will be a first step in a journey to oss contributions, I'll probably be sleeping when you get back.

I forgot to mention some more step that need to be done after you switch to the develop branch:

git submodule init
git submodule update

what this does is get the files that need to be in BuildSystem folder which are used across different SharpArch project, after you have the BuildSystem, if you open the solution and try to build, it will fail because there are some files which we generate in the build scripts (files used for assembly versioning), to generate this files run the file:

Build\BuildAndPackage.bat

Which should generate the files and try to build the solution, I am not sure if it builds/tests pass at the moment, you might need to fix some things ( But you should be able to work on the solution now :) but once build succeeds, when you run the command, you will get the dlls in:

Drops\

Hope it all goes well!

Seif


Seif Attar

unread,
Feb 11, 2012, 9:18:23 PM2/11/12
to sharp-arc...@googlegroups.com
Paul, I have just pushed a 1.0RC of the contrib out to nuget. you
should still configure github anyways! ;)

So, in the project where you were using SharpArchContrib to start
with, remove all references of SharpArchContrib, clean the solution,
then from the nuget package manager console run:

install-package SharpArchContrib.Castle -pre

the pre is because this is a pre release, and to use this feature you
would need the latest version of nuget (1.6)

Seif Attar

unread,
Feb 11, 2012, 9:19:26 PM2/11/12
to sharp-arc...@googlegroups.com
You will also need to install the package to the web project.

Paul

unread,
Feb 12, 2012, 1:20:20 AM2/12/12
to S#arp Architecture
Hi Seif,

In regards to the web project, am I to use nuget and if so, what
command do I want to run?

I understand the need to get the web project. I added the sharp arch
contrib and castle dll's based off the code from github, but I'm
getting "looking for version 2.5.1 of Castle.Windsor". I think once I
add that in I should be hopefully be good. Then I can finally test to
see if the transaction stuff works :P

On a related note, the code I got from Github (the /develop branch)
builds successfully. Not sure if that means anything at this point,
but I thought I'd let you know :)

Thanks!
> >>> >> >> >> >> > >        ...
>
> read more »

Seif Attar

unread,
Feb 12, 2012, 6:04:38 AM2/12/12
to sharp-arc...@googlegroups.com
You would use the same command for the web project

install-package SharpArchContrib.Castle -pre

I am surprised you got that Castle version problem, as the templify
project should already have binding redirects for that in the
web.config.

TO fix that, add this to the end of your web.config (before </configuration>):

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json"
publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.7.0" newVersion="4.0.7.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Castle.Windsor"
publicKeyToken="407dd0808d44fbdc" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>

Paul

unread,
Feb 12, 2012, 10:53:31 PM2/12/12
to S#arp Architecture
Hey Seif,

I ran nuget and it seemed to install everything ok. I had to include
the web.config changes. However, upon running it, I got the following
error where it was trying to inject one of the tasks into the
controllers:

Can't create component 'myproject.Tasks.Tasks.Item1' as it has
dependencies to be satisfied.

'myproject.Tasks.Tasks.Item1' is waiting for the following
dependencies:
- Service
'SharpArch.NHibernate.Contracts.Repositories.INHibernateRepository`1[[myproject.Domain.Entities.Item1,
myproject.Domain, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null]]' which was not registered.

Also, in my original component registrar, the AddGenericComponents was
failing as duplicate keys were being inserted. I commented it out for
now. But I'm wondering if the error I'm getting above is due to the
AddCustomRepositoriesTo method. Here is my ComponentRegistrar class:

public class ComponentRegistrar
{
public static void AddComponentsTo(IWindsorContainer
container)
{
AddGenericRepositoriesTo(container);
AddCustomRepositoriesTo(container);
}

private static void AddCustomRepositoriesTo(IWindsorContainer
container)
{
container.Register(

AllTypes.Pick().FromAssemblyNamed("myproject.Infrastructure").WithService.FirstNonGenericCoreInterface(
"myproject.Domain"));

I noticed that the two method calls in AddCustomRepositoriesTo are
obsolete, thus I'm not sure if the error I am receiving is due to
that. If you could shed any light, that would be great. I really
want to get this resolved so I can get the Transaction attribute
tested, but I'm also not trying to spend a huge amount of time on it
either. I can get around the transaction with some using statements.
I don't want to go down that road unless I can't get this to work.

Thanks!

On Feb 12, 6:04 am, Seif Attar <i...@seifattar.net> wrote:
> You would use the same command for the web project
>
> install-package SharpArchContrib.Castle -pre
>
> I am surprised you got that Castle version problem, as the templify
> project should already have binding redirects for that in the
> web.config.
>
> TO fix that, add this to the end of your web.config (before </configuration>):
>
>   <runtime>
>     <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
>       <dependentAssembly>
>         <assemblyIdentity name="Newtonsoft.Json"
> publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
>         <bindingRedirect oldVersion="0.0.0.0-4.0.7.0" newVersion="4.0.7.0" />
>       </dependentAssembly>
>       <dependentAssembly>
>         <assemblyIdentity name="Castle.Windsor"
> publicKeyToken="407dd0808d44fbdc" culture="neutral" />
>         <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
>       </dependentAssembly>
>     </assemblyBinding>
>   </runtime>
>
> >> >>> >> >> >> >> > > Currently, I am creating the container...
>
> read more »

Seif Attar

unread,
Feb 13, 2012, 3:37:54 AM2/13/12
to sharp-arc...@googlegroups.com
Where is the rest of ur component registrar?

How are application services registered/instantiated?

Did you use templify to create this project?



Sent from my phone


Paul

unread,
Feb 13, 2012, 11:46:36 AM2/13/12
to S#arp Architecture
That is it for the component registrar. Beyond that, I have only this
in the global.asax:

protected virtual IWindsorContainer InitializeServiceLocator()
{
IWindsorContainer container = new WindsorContainer();


SharpArchContrib.Castle.CastleWindsor.ComponentRegistrar.AddComponentsTo(container);

ControllerBuilder.Current.SetControllerFactory(new
WindsorControllerFactory(container));


container.RegisterControllers(typeof(HomeController).Assembly);
ComponentRegistrar.AddComponentsTo(container);

ServiceLocator.SetLocatorProvider(() => new
WindsorServiceLocator(container));

return container;
}

As for the application services, I do not have a separate project for
one

I did not use templify to create the project, I had used the Northwind
sample as a starting point and added projects to mine based on what
Northwind have (minus the services layer)



On Feb 13, 3:37 am, "Seif Attar" <i...@seifattar.net> wrote:
> Where is the rest of ur component registrar?
> How are application services registered/instantiated?
> Did you use templify to create this project?Sent from my phoneOn 13 Feb 2012 03:53, Paul <sho...@gmail.com> wrote:Hey Seif,
> > >> >>> on your local ...
>
> read more »

Seif Attar

unread,
Feb 13, 2012, 2:04:50 PM2/13/12
to sharp-arc...@googlegroups.com
ok, looking at the cookbook (which is using the latest code, and is
properly configured), the AddGenericRepositories method has the
following implementation, try changing your code for that method to
this:

private static void AddGenericRepositoriesTo(IWindsorContainer
container)
{

container.Register(
Component.For(typeof(IEntityDuplicateChecker))
.ImplementedBy(typeof(EntityDuplicateChecker))
.Named("entityDuplicateChecker"));

container.Register(
Component.For(typeof(INHibernateRepository<>))
.ImplementedBy(typeof(NHibernateRepository<>))
.Forward(typeof(IRepository<>))
.Named("nhibernateRepositoryType"));

container.Register(
Component.For(typeof(INHibernateRepositoryWithTypedId<,>))
.ImplementedBy(typeof(NHibernateRepositoryWithTypedId<,>))
.Forward(typeof(IRepositoryWithTypedId<,>))
.Named("nhibernateRepositoryWithTypedId"));

container.Register(
Component.For(typeof(ISessionFactoryKeyProvider))
.ImplementedBy(typeof(DefaultSessionFactoryKeyProvider))
.Named("sessionFactoryKeyProvider"));

container.Register(

Component.For(typeof(SharpArch.Domain.Commands.ICommandProcessor))

.ImplementedBy(typeof(SharpArch.Domain.Commands.CommandProcessor))
.Named("commandProcessor"));

}

If that fails, can you upload the project somewhere so I can look at it?

Paul

unread,
Feb 14, 2012, 5:27:47 PM2/14/12
to S#arp Architecture
Hey Seif,

I don't think that is the problem, I think the issue is this line
within the InitializeServiceLocator() function:

SharpArchContrib.Castle.CastleWindsor.ComponentRegistrar.AddComponentsTo(container);

It seems to add those repositories. If I comment out the
AddGenericRepositoriesTo call, it works, but does not add the custom
repositories correctly from what I can tell which gives me the error I
described a few other posts.
> On 13 February 2012 16:46, Paul <shor...@gmail.com> wrote:
>
>
>
>
>
>
>
> > That is it for the component registrar.  Beyond that, I have only this
> > in the global.asax:
>
> > protected virtual IWindsorContainer InitializeServiceLocator()
> >        {
> >            IWindsorContainer container = new WindsorContainer();
>
> > SharpArchContrib.Castle.CastleWindsor.ComponentRegistrar.AddComponentsTo(container);
>
> >            ControllerBuilder.Current.SetControllerFactory(new
> > WindsorControllerFactory(container));
>
> > container.RegisterControllers(typeof(HomeController).Assembly);
> >            ComponentRegistrar.AddComponentsTo(container);
>
> >            ServiceLocator.SetLocatorProvider(() => new
> > WindsorServiceLocator(container));
>
> >            return container;
> >        }
>
> > As for the application services, I do not have a separate project for
> > one
>
> > I did not use templify to create the project, I had used the Northwind
> > sample as a starting point and added projects to mine based on what
> > Northwind have (minus the services layer)
>
> > On Feb 13, 3:37 am, "Seif Attar" <i...@seifattar.net> wrote:
> >> Where is the rest of ur component registrar?
> >> How are application services registered/instantiated?
> >> Did you use templify to create this project?Sent from my phoneOn 13 Feb 2012 03:53, Paul <shor...@gmail.com> wrote:Hey Seif,
> >> > >> >> On 11...
>
> read more »

Seif Attar

unread,
Feb 14, 2012, 6:07:52 PM2/14/12
to sharp-arc...@googlegroups.com
What makes you think it is a problem with that line?

To make sure it is not a problem with the contrib code, I used the
contrib transaction in a branch on the cookbook:

https://github.com/sharparchitecture/Sharp-Architecture-Cookbook/tree/contrib

Adding/Editing ProductModel works as expected when running the project.

Have you tried changing the component registrar as I suggested and it
didn't work for you??

Paul

unread,
Feb 14, 2012, 6:08:19 PM2/14/12
to S#arp Architecture
Hey Seif,

It appears to be this line in the InitializeServiceLocator():

SharpArchContrib.Castle.CastleWindsor.ComponentRegistrar.AddComponentsTo(container);

It seems to add those repositories automatically. However, when I
comment out my call to AddGenericRepositoriesTo(), the repositories
seem to be added, however, I get the error I mentioned beforehand. It
seems it does not add the custom repositories.

I hope that helps. If anything, is there another way I could get into
contact with you?

Thanks!
> On 13 February 2012 16:46, Paul <shor...@gmail.com> wrote:
>
>
>
>
>
>
>
> > That is it for the component registrar.  Beyond that, I have only this
> > in the global.asax:
>
> > protected virtual IWindsorContainer InitializeServiceLocator()
> >        {
> >            IWindsorContainer container = new WindsorContainer();
>
> > SharpArchContrib.Castle.CastleWindsor.ComponentRegistrar.AddComponentsTo(container);
>
> >            ControllerBuilder.Current.SetControllerFactory(new
> > WindsorControllerFactory(container));
>
> > container.RegisterControllers(typeof(HomeController).Assembly);
> >            ComponentRegistrar.AddComponentsTo(container);
>
> >            ServiceLocator.SetLocatorProvider(() => new
> > WindsorServiceLocator(container));
>
> >            return container;
> >        }
>
> > As for the application services, I do not have a separate project for
> > one
>
> > I did not use templify to create the project, I had used the Northwind
> > sample as a starting point and added projects to mine based on what
> > Northwind have (minus the services layer)
>
> > On Feb 13, 3:37 am, "Seif Attar" <i...@seifattar.net> wrote:
> >> Where is the rest of ur component registrar?
> >> How are application services registered/instantiated?
> >> Did you use templify to create this project?Sent from my phoneOn 13 Feb 2012 03:53, Paul <shor...@gmail.com> wrote:Hey Seif,
> >> > >> >> On 11...
>
> read more »

Seif Attar

unread,
Feb 14, 2012, 6:11:19 PM2/14/12
to sharp-arc...@googlegroups.com
skype? saifattar

On 14 February 2012 23:08, Paul <sho...@gmail.com> wrote:

Seif Attar

unread,
Feb 14, 2012, 6:20:20 PM2/14/12
to sharp-arc...@googlegroups.com
Paul, you still haven't answered my question about why you think it is
that line, I had checked the contrib code when you first metioned
getting an error about a duplicate key, and contrib doesn't register
any repositories.

I just changed the ComponentRegistrar to use your version of the
AddGenericRepositories, and I got a duplicate key exception! If you
have tried using the code I gave you and it doesn't work, you can
contact me via skype, I will be online for another 30 mins.

Paul

unread,
Feb 16, 2012, 1:20:39 PM2/16/12
to S#arp Architecture
Hey Seif,

After our discussion, I got the code in which made the site run,
however, I am still facing the transaction issue. Do you have a few
mins I could bug you over Skype?

Thanks!

On Feb 14, 6:20 pm, Seif Attar <i...@seifattar.net> wrote:
> Paul, you still haven't answered my question about why you think it is
> that line, I had checked the contrib code when you first metioned
> getting an error about a duplicate key, and contrib doesn't register
> any repositories.
>
> I just changed the ComponentRegistrar to use your version of the
> AddGenericRepositories, and I got a duplicate key exception! If you
> have tried using the code I gave you and it doesn't work, you can
> contact me via skype, I will be online for another 30 mins.
>
> On 14 February 2012 23:11, Seif Attar <i...@seifattar.net> wrote:
>
>
>
>
>
>
>
> > skype? saifattar
>
> >>> >> > > On Feb 11, 9:19 pm,...
>
> read more »

Seif Attar

unread,
Feb 16, 2012, 1:24:44 PM2/16/12
to sharp-arc...@googlegroups.com
Not within 3 hours, is the issue that the transaction is not being started at all?



Sent from my phone


Paul

unread,
Feb 16, 2012, 1:33:19 PM2/16/12
to S#arp Architecture
It appears to be. What happens is that the task executes and writes
to the first table in the DB, then when I throw the exception when
trying to write to the second table in the DB, the record is still in
the first table. Based on our previous discussions, I marked the
method virtual. Is there something I need to configure upon
application startup?


On Feb 16, 1:24 pm, "Seif Attar" <i...@seifattar.net> wrote:
> Not within 3 hours, is the issue that the transaction is not being started at all?Sent from my phoneOn 16 Feb 2012 18:21, Paul <sho...@gmail.com> wrote:Hey Seif,
> > >>> >> ...
>
> read more »

Seif Attar

unread,
Feb 16, 2012, 1:55:33 PM2/16/12
to sharp-arc...@googlegroups.com
Shouldn't be, check the contrib wiki to make sure you haven't missed anything.



Sent from my phone


Paul

unread,
Feb 16, 2012, 5:14:06 PM2/16/12
to S#arp Architecture
I've taken a look and I seem to have everything it has mentioned in
place. I'll keep scouring. I know it's now about 10pm your time now
or so. If you have some time tomorrow, let me know. A second pair of
eyes might be what I need.

On Feb 16, 1:55 pm, "Seif Attar" <i...@seifattar.net> wrote:
> Shouldn't be, check the contrib wiki to make sure you haven't missed anything.Sent from my phoneOn 16 Feb 2012 18:33, Paul <sho...@gmail.com> wrote:It appears to be. What happens is that the task executes and writes
> > > >>> >> public static void ...
>
> read more »

Paul

unread,
Feb 16, 2012, 6:42:13 PM2/16/12
to S#arp Architecture
Hi Seif,

It has been resolved based on our discussion. I was not injecting a
business logic class into the controller like I should have (I was
instantiating it in the controller instead). Due to that fact, the
Castle interceptors could not see it and thus the Transaction
attribute was ignored. That was mostly due to my lack of knowledge of
Castle and Dependency Injection.

So, to sum it all up (for myself and others), injection is key to the
use of the Sharp Architecture Transaction attribute. Anything that is
using the Transaction attribute must be injected. In my case, I
injected the business logic class into a controller's constructor.

Two other things of note if you use the Transaction attribute in a
class:

1. It must either inherit from an interface (which is in turn
injected) or
2. The method must be marked virtual

:)


On Feb 16, 5:14 pm, Paul <shor...@gmail.com> wrote:
> I've taken a look and I seem to have everything it has mentioned in
> place.  I'll keep scouring.  I know it's now about 10pm your time now
> or so.  If you have some time tomorrow, let me know.  A second pair of
> eyes might be what I need.
>
> On Feb 16, 1:55 pm, "Seif Attar" <i...@seifattar.net> wrote:
>
>
>
>
>
>
>
> > Shouldn't be, check the contrib wiki to make sure you haven't missed anything.Sent from my phoneOn 16 Feb 2012 18:33, Paul <shor...@gmail.com> wrote:It appears to be. What happens is that the task executes and writes
> > to the first table in the DB, then when I throw the exception when
> > trying to write to the second table in the DB, the record is still in
> > the first table. Based on our previous discussions, I marked the
> > method virtual. Is there something I need to configure upon
> > application startup?
> > On Feb 16, 1:24 pm, "Seif Attar" <i...@seifattar.net> wrote:
> > > Not within 3 hours, is the issue that the transaction is not being started at all?Sent from my phoneOn 16 Feb 2012 18:21, Paul <shor...@gmail.com> wrote:Hey Seif,
Reply all
Reply to author
Forward
0 new messages