Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8815445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:22:49+00:00 2026-06-14T04:22:49+00:00

Scenario: I’m using the dependency-injection component as a stand-alone component. No bundles/symfony-framework and stuff.

  • 0

Scenario:

  • I’m using the dependency-injection component as a stand-alone component. No bundles/symfony-framework and stuff.
  • I have a set of services all being responsible for similar things, e.g. for writing data to the hard disk by different ways (e.g. by ftp, direct file operations, storing into a db, …)
  • Each of these services requires different configuration (e.g. sql credentials, ftp credentials, …)
  • I want to define one of these services as the “general service to use” for other services to have a dependency on.
  • Which service to use is configured by a parameter

Example:

Given these simplified parameter and service definitions:

<parameter key="file.adapterType">direct</parameter>
<service id="file.db" />
<service id="file.ftp" />
<service id="file.direct" />

I’d like to define an alias to the service I actually want to use

<service id="file.adapter" alias="file.%file.adapterType%"/>

for other services simply relying on this service:

<service id="photos">
    <argument type="service" id="file.adapter" />
</service>

What I have tried so far:

  • Defining an alias with an parameter in it’s alias-id. However the parameter within the alias-id does not get resolved.
  • Defining the id directly within the argument-tag – again the parameter is not resolved her:

    <service id="photo">
        <argument type="service" id="file.%file.adapterType%" />
    </service> 
    
  • Creating a factory. The get-method receives the parameter and the di-container and returns the corresponding service:

    public function get(ContainerInterface $container, $parameter) 
    {
        return $container->get('file.' . $parameter);
    }
    

    However the container does not register itself as a service. Registering it beforehand does not take affect when loading the configuration from a file (resulting in an error message “service ‘container’ not found”):

    $container->set("container", $container);
    $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/services'));
    $loader->load('fileadapter.xml'); // << gives error
    $container->get("container"); // << working
    

Other alternatives?

I can’t set the alias after loading the configuration file as there are services within the file that have a dependency on the alias.

Anyone got other ideas on how to handle this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T04:22:50+00:00Added an answer on June 14, 2026 at 4:22 am

    Actually, I believe you were on the right track with the third bullet point in the “What I’ve tried so far” section, except that the service container does register itself as a service, but it’s called service_container, not container.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Scenario first :- I'm using Entity Framework to do some queries, to build my
Scenario: An MVC3 app that uses constructor injection to provide services for a given
Scenario I'm using a Custom IPrincipal and IIdentity to do asp.net authorization. I set
Scenario: We have a scheduler which is using JDBC Job Store. Quartz version is
Scenario While using the Maven Ant Task artifact:deploy , I'm encountering the error java.lang.OutOfMemoryError:
Scenario: Every page on the website will have a menu bar at the top
Scenario 1: If I have a Great Grandpa ancestor (let's name him A); And
Scenario: I have imported the data from SQl Server to HDFS. The data stored
Scenario Say for example I have the following: 1 | 2 | 3 4
Scenario: I have an application that pulls data from a SQL database as well

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.