File repository class

Hello;
In my 7.17 version i create a file repository override class and it work correctly
when I try to upgrade to 8,2,1 the FileService core class change and it create fileRepository object based on interface not class (ClassFactory.Get) and it run based method loadFile not override one.
Is it any solution to set the the default class for interface

Like 0

Like

5 comments

Hi,

Yes, starting from version 8.x, Creatio uses dependency injection (DI) more actively, including for services like IFileRepository, which is now resolved via ClassFactory.Get<IFileRepository>().

To override the default implementation, you can register your custom class as the default for the interface in the dependency container.
 

Solution: Register your class for the interface

You have to create your own AppEventListener and bind your class to the appropriate interface there.

 

public class UsrAppEventListener : AppEventListenerBase
{
	public override void OnAppStart(AppEventContext context) 	{
		base.OnAppStart(context);
		ClassFactory.Bind<IFileRepository, CustomFileRepository>(reuseType: ReuseType.Singleton);
    }
}

 

Where:

  • CustomFileRepository is your custom class that implements IFileRepository
  • ReuseType.Singleton (or None) depends on your usage

⚠️ Important: Ensure your class fully implements the IFileRepository interface.

This way, when FileService calls ClassFactory.Get<IFileRepository>(), it will receive your custom implementation.

TU Irina

Tomasz Branicki,

Hi Irina.
I finally manage to upgrate creatio properly so i can try your sollution.
write now i gut such error

Terrasoft.Core.InstanceActivationException
 HResult=0x80131600
 Message=Error creating an instance of the "Terrasoft.Configuration.IFileRepository" class
 Source=<Cannot evaluate the exception source>
 StackTrace:
<Cannot evaluate the exception stack trace>

 This exception was originally thrown at this call stack:
   [External Code]

Inner Exception 1:
ActivationException: Error activating IFileRepository
More than one matching bindings are available.
Matching bindings:
 1) binding from IFileRepository to FileRepository
 2) binding from IFileRepository to UsrFileRepository
Activation path:
 1) Request for IFileRepository

Suggestions:
 1) Ensure that you have defined a binding for IFileRepository only once.

My class is describe like that

    [Terrasoft.Core.Factories.Override]
   public class UsrFileRepository : FileRepository.

can you give me a hand :)

regards
Tomek

Iryna Oriyenko,

Hi Irina.
I finally manage to upgrate creatio properly so i can try your sollution.
write now i gut such error

Terrasoft.Core.InstanceActivationException
 HResult=0x80131600
 Message=Error creating an instance of the "Terrasoft.Configuration.IFileRepository" class
 Source=<Cannot evaluate the exception source>
 StackTrace:
<Cannot evaluate the exception stack trace>

 This exception was originally thrown at this call stack:
   [External Code]

Inner Exception 1:
ActivationException: Error activating IFileRepository
More than one matching bindings are available.
Matching bindings:
 1) binding from IFileRepository to FileRepository
 2) binding from IFileRepository to UsrFileRepository
Activation path:
 1) Request for IFileRepository

Suggestions:
 1) Ensure that you have defined a binding for IFileRepository only once.

My class is describe like that

    [Terrasoft.Core.Factories.Override]
   public class UsrFileRepository : FileRepository.

can you give me a hand :)

regards
Tomek

Iryna Oriyenko,

Hi Iryna;
I find solution
I used rebind except bind.
thank you for help

 

regards Tomek

Show all comments