Hi,
I thank you for your helping hand :-)
The app is a sort of accountancy program, but extremely specialized on
financial products.
It is a mix of vb.net and c#, the UI is on VB, the data access layer
(castle + nhibernate active record) is on c#, of course my problem is
on UI...
The original project has dependencies on nano/pico container and
Castle, the latest stable version I found for .net 1.1
I edited the code in order to have it run under .net 4, then I
substituted the old castle with the latest for .Net 4 keeping the old
containers.
It worked partially, since I had threading problems, memory leaks and
so on, having actually 2 different castle at work: the .net4 version
and the .net 1.1 referenced by containers.
I therefore decided to switch to Windsor...
The castle related code starts in a custom project that does just the
bootstrap:
Dim containerBuilderFacade As containerBuilderFacade = New
AttributeBasedContainerBuilderFacade
container = containerBuilderFacade.Build(New String()
{"myProject.UI.dll"})
container.RegisterComponentImplementation(GetType(IPresenterFactory),
GetType(PresenterFactory), New ConstantParameter() {New
ConstantParameter(container)})
container.Verify()
then i prepare the castle...
Public Shared Sub SetUpCastle()
Dim source As IConfigurationSource =
ConfigurationSettings.GetConfig("activerecord")
ActiveRecordStarter.Initialize(source, GetType(Agreement),
GetType(Utente)... and so on for each class dealing with active
record.
(I suppose that this last method is not related at all with Windsor)
each form (view) is decoraded with
<RegisterWithContainer(ComponentAdapterType.NonCaching)> _
Public Class Agreement
Implements IViewAgreement
...
(some of them has the caching option active)
all the views implement an interface of course.
this interface defines methods and properties that must be accessed by
the presenter, as well some events that happen on the form but are
handled on the presenter.
On the presenter side, each one has the same decoration...
Namespace Presenters
<RegisterWithContainer(ComponentAdapterType.NonCaching)> _
Public Class AgreementPresenter
Implements IAgreementPresenter
Private view As IViewAgreement
the presenter iterface contains
ReadOnly Property View() As IViewAgreement
some methods related to settings persistance (managed by the base
presenter from which all presenters inherits) and some events related
to business logic, raised on the presenter and subscribed by a
different presenter. (it is a master detail data set: when the
presenter handling a "record" gets a "save" command it raises a
"saved" event so that the presenter handling the list of records can
update itself.
To open a form, we do this on the main presenter (the presenter of the
main form of course)
Dim presenter As IPresenter
Select Case vocemenu
Case "Agreement"
presenter =
presenterFactory.Find(GetType(AgreementPresenter))
...
here Presenter factory is
Public Interface IPresenterFactory
Function Find(ByVal type As Type) As IPresenter
Function Find(ByVal type As Type, ByVal solaLettura As Boolean) As
IPresenter
End Interface
and finally we get to the point...
Public Class PresenterFactory
Implements IPresenterFactory
Private container As IMutablePicoContainer
Public Sub New(ByVal container As IMutablePicoContainer)
Me.container = container
End Sub
Public Function Find(ByVal type As Type) As IPresenter Implements
IPresenterFactory.Find
Dim presenter As IPresenter
presenter = container.GetComponentInstance(type)
Return presenter
End Function
What I did to upgrade this code is:
Avoid the decoration <register with container> (I use the register by
mask of Windsor, moreover the compiler does not recognize them at all
with new castle + windsor)
tried to play with the IMutablePicoContainer substituting it with
Windsor.
I got partial results: the app compiles, the splash screen appears (no
presenters here :-) ) but the find that tries to instantiate the main
form fails.
I inspected my windsor container and it seems that actually contains
tons of info about classes but for some reason it does not work.
I do not have here the exact code in my Find (it is on the office pc)
but I think that I gave you tons of info (maybe too much) to have a
proper idea about my problem.
Many thanks for your time reading all this, and thanks in advance for
any help you might provide.
Regards
Luca
On 30 Gen, 18:57, José F. Romaniello <[email protected]> wrote:
> I usually do MVP on winform like this:
>
> 1-my form implements an interface like IEditCustomerView.
> 2-my EditCustomerPresenter depends on IEditCustomerView, constructor
> injection.
>
> Would you mind to show us how do you do MVP?, please show some simple
> classes and ill help you
>
> 2011/1/30, luca101010 <[email protected]>:
>
>
>
>
>
>
>
>
>
> > Hi Krzysztof,
>
> > actually I know that page, but I cannot find proper samples of MVP on
> > Windows form using Windsor.
> > I tried to apply the "RuleTheCastle" quickstart and several samples,
> > but my application fails when I need to instantiate the couple
> > presenter-view.
> > I add to Windsor the "presenter" classes and the "view" classes, using
> > the add from assembly feature, but it seems that presenters cannot
> > recognize theyr linked form.
>
> > Most samples I find have a form with a presenter and and interface
> > between them, on my application I have instead an interface
> > implemented in the form and a different one implemented in presenters.
> > I cannot understand if this structure is compatible with Windsor since
> > I have 1 more interface that most samples found on the documentation.
>
> > So I would like to avoid architectural mistakes and start with a
> > proper idea about how to perform this upgrade.
> > Please note that my version of picocontainer contains an explicit
> > reference to Castle so I suppose it was somewhat hacked from a pure
> > standard conteiner to let it work on MVP.
>
> > Anyway thanks for your kind reply.
>
> > Regards
> > Luca
>
> > On 30 Gen, 15:56, Krzysztof Koźmic <[email protected]> wrote:
> >> Luca,
>
> >> have you looked at Windsor's documentation page?
>
> >> It is discussing patterns and scenarios in many detauls so it should
> >> answer most of your
> >> questions.http://stw.castleproject.org/Windsor.MainPage.ashx
>
> >> cheers,
> >> Krzysztof
>
> >> On 31/01/2011 12:52 AM, luca101010 wrote:
>
> >> > Hello,
>
> >> > I am working on the upgrade of a big applition (windows forms)
> >> > from .Net 1.1 to 4.
>
> >> > I have managed to upgrade most of the code, correcting the most
> >> > obvious errors, I have upgraded both castle and Hibernate to the
> >> > latest versions and I am now working on containers.
>
> >> > The app uses a MVP archietecture, and nano / pico containers to hold
> >> > the classes in order to tie presenters and forms.
>
> >> > I would like to get rid of them, moving to Castle Windsor, but I do
> >> > not find information about if it can be done and what might be the
> >> > risks.
>
> >> > Can you help me in understanding best practices, tricks and
> >> > suggestions to perform this upgrade?
> >> > The biggest problems I am having are about remapping the "setup" calls
> >> > of containers to proper Windsor calls.
>
> >> > Thanks in advance for your kind help.
>
> >> > Luca
>
--
You received this message because you are subscribed to the Google Groups
"Castle Project Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/castle-project-users?hl=en.