Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Passing generic delegate to business objects
Message
From
29/10/2008 09:43:07
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
 
 
To
28/10/2008 14:46:10
General information
Forum:
ASP.NET
Category:
Class design
Environment versions
Environment:
VB 9.0
OS:
Vista
Network:
Windows 2008 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01357813
Message ID:
01358054
Views:
42
Andrus,

>Winforms UI assembly has static FormManager.FormCreator method which creates
>forms taking entity as parameter.
>I need to pass this method to business objects in business assembly so that
>business methods can also create
>forms but does not have reference to UI assembly.
>
>Childentity1 and other business entities are avaliable to UI assembly.
>I want from UI assembly to pass form manager method so that business objects
>can call it by passing different business entities to this method.
>
>In real code FormCreator uses TEntity much more. It creates list
>of TEntity objects
>and retrieves data for editing which may be changed by business object
>worker method. Business object also passes query parameters to
>FormCreator method which are not shown in this example.
>I can probably pass entity name instead of type and use reflection but I'm
>interested how to do this without reflection.
>
>I tried code below but got compile errows shown in comments.
>
>
>How to fix ?
>
>
>
>////// This code is in Entry, Winforms UI assembly and has references to 
>business assembly
>
>using System.Windows.Forms;
>public delegate void ActivateEntityForm<TEntity>();
>
>class test
>{
>    static void Main()
>    {
>        //Invalid expression term '>'
>        new 
>Customer().DoBusinessLogicAndShowResultFormsUsingFormManager(FormManager.FormCreator<>);
>    }
>}
>
>
>public static class FormManager
>{
>    public static void FormCreator<TEntity>()
>    {
>        Form f = new Form();
>        f.Text = typeof(TEntity).Name;
>        f.Show();
>    }
>}
>
>/// Code below resides in business assembly and should not have references 
>to assembly above
>
>class Customer
>{
>    public void 
>DoBusinessLogicAndShowResultFormsUsingFormManager<TChildEntity>(
>        ActivateEntityForm<TChildEntity> formCreator)
>    {
>        //The variable 'x' cannot be used with type arguments
>        formCreator<Childentity1>();
>        formCreator<Childentity2>();
>    }
>
>}
>
>class Childentity1 { }
>class Childentity2 { } 
>
I am not sure I understand your idea so don't get offended if I get it wrong. It sounds like you are asking for the UI to know all about (have a reference to) the business tier AND the business tier to know about (have a reference to) the UI. It may be that you are having problems because you are attempting to create a circular reference by fooling it. Why is it you need business logic to create forms? Can you just raise an event in the business logic that allows the UI to create it's own form?

Tim
Timothy Bryan
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform