Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > LLBLGen Pro Runtime Framework> Injecting an instance (of a custom class) into a TypedList
 

Pages: 1
LLBLGen Pro Runtime Framework
Injecting an instance (of a custom class) into a TypedList
Page:1/1 

  Print all messages in this thread  
Poster Message
sherman
User



Location:
Malaga - Spain
Joined on:
31-Jul-2007 18:58:13
Posted:
9 posts
# Posted on: 10-Mar-2008 13:01:08.  
I want to inject (via LLBGen's DI mechanism) a "filter" (my custom class) into a TypedList. Is it possible?

Is this one the correct way?:

Sample TypedList
Code:
    public partial class MySampleTypedList
    {
            ...            
        private Filter _filterToUse;
        public Filter FilterToUse
        {
            get { return filterToUse; }
            set { filterToUse = value; }
        }
        ...
    }


Class to inject
Code:
    [DependencyInjectionInfo(typeof(TypedListBase2), "FilterToUse")]
    [Serializable]
    public class Filter
    {
        public Filter()
        {
        }
        ...        
    }


Code:
        ...
        MySampleTypedList sampleTypedList = new MySampleTypedList();
        DependencyInjectionInfoProviderSingleton.PerformDependencyInjection(sampleTypedList);
        
        DataAccessAdapter adapter = new DataAccessAdapter();
        adapter.FetchTypedList(sampleTypedList);
        ...
        

Always I get an System.TypeInitializationException "The type initializer for 'SD.LLBLGen.Pro.ORMSupportClasses.DependencyInjectionInfoProviderSingleton' threw an exception." in DependencyInjectionInfoProviderSingleton.PerformDependencyInjection(sampleTypedList);


LLBLGen Pro 2.5 (August 27th, 2007)
Adapter / .NET 2.0
  Top
daelmo
Support Team



Location:
Guatemala City
Joined on:
28-Nov-2005 23:35:24
Posted:
8125 posts
# Posted on: 11-Mar-2008 02:12:13.  
Hi sherman, accordingly to the Manual, you have to perform the injection at the constructor of the class. This is copied from LLBLGenPro Help - Concepts - Dependency Injection and Inversion of Control:
Quote:
The DI mechanism in LLBLGen Pro is used for injecting objects into entities: entity classes are prepared to get the objects they depend on injected by the DI mechanism, other classes are not. This doesn't mean you can't enable these classes to use the DI mechanism, because you can. All you have to do is call the DependencyInjectionProvider to inject the objects the instance relies on, from the constructor of the class. Do this with the following code: (For entities, you don't have to do anything, it's been taken care of for you. Only use the following code if you want to use the LLBLGen Pro DI mechanism to inject objects into classes not yet prepared for DI).

Code:
C#
DependencyInjectionInfoProviderSingleton.PerformDependencyInjection(this);


After using this line of code in the constructor of your class, you can use code like:
Code:
C#
MyClass c = new MyClass();


and c will get all objects to inject into an instance of MyClass injected. For entities, you don't have to do anything, it's been taken care of for you.


If you still have troubles, please post the whole exception stack trace.

Cheers.


David Elizondo
LLBLGen'ing (articles and code snippets) | linkedin | twitter
 
Top
sherman
User



Location:
Malaga - Spain
Joined on:
31-Jul-2007 18:58:13
Posted:
9 posts
# Posted on: 11-Mar-2008 09:39:32.  
Forget it, I've overlooked that phrase ("from the constructor of the class") Embarrassed

Thanks for the quick reply!
  Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.