IOC not initialized?

Issue #5 closed
Former user created an issue

It appears to me that any attempt to use the IOC will always result in this code:

  FGetInstance := function(Service: PTypeInfo; Key: string): TValue
    begin
      raise EInvalidOperationException.Create('IoC is not initialized.');
    end;

being executed.

Or, put another way, anytime you try to use the [Security('foo')] attribute, you'll get the exception above.

I can find no way to initialize the IOC.....?

Or am I missing something?

Comments (3)

  1. Former user Account Deleted

    IoC is a static entity used for service location and must be initialized to be used.

    If you are building a typical MVVM application then the following line will initialize the framework (including IoC) by running the default bootstrapper (TSpringBootstrapper<TRootModel>).

    Application.Start<IAppViewModel>();
    

    If you are not running your application in this way then you need to configure IoC before using it. You have to initialize these methods:

    IoC.GetInstance := GetInstance;
    IoC.GetAllInstances := GetAllInstances;
    

    Take a look into DSharp.PresentationModel.SpringBootstrapper.pas and DSharp.PresentationModel.Bootstrapper.pas to see how we initialize it with spring container.

  2. Former user Account Deleted

    Marko --

    All that just to use the [Security] attribute? Yikes!

    Thanks -- I'll look into it.

  3. Former user Account Deleted

    You could also provide you own TSecurityAspect implementation by copying unit DSharp.Aspects.Security and writing your own password validation (the current one seems like it is written for demo purposes - it uses hard-coded passwords).

  4. Log in to comment