Tina Fontaine asked for help before she died childrens advocate

first_imgSAGKEENG FIRST NATION, Man. _ A report into the death of a Manitoba Indigenous teenager says she asked for help in the weeks before she was found dead in the Red River, but social agencies told her there were no beds available.The report by Manitoba children’s advocate says that essentially left Tina Fontaine homeless and at risk for sexual exploitation.— CityNews Winnipeg (@CityNewsWPG) March 12, 2019The report by Manitoba children’s advocate says that essentially left Tina Fontaine homeless and at risk for sexual exploitation.“Tina had acute mental health needs following her father’s death but she was never provided with a single counselling session or other cultural healing, despite ongoing assessments and recommendations that this was a critical need in her life,” reads the reports from Daphne Penrose.“Further, Tina developed acute addictions in her final months of life and used many different drugs and alcohol but was unable to find the help she needed that would support her to address her underlying pain.”READ MORE: System failed Manitoba girl returned to parent without support, checks: advocateSocial workers and others ignored multiple signs that Tina was spiralling downward and in danger according to the report.Penrose said following the death of Tina’s father, victim services did not follow through with the child to provide counselling support, “despite her right to this services and the obligation of victim services to provide it during the two and half years in which they were involved with Tina’s family.”The child advocate’s report also looked into the sexual exploitation of the province’s youth–something Penrose says Manitoba has a “shameful reputation for”.READ MORE: Small things become scary, says Indigenous teen of Fontaine case, MMIWGThe report also details how Fontaine’s family was affected by a history of residential schools, the ’60s Scoop, and child-welfare agencies.“She carried a burden that was not her own,” Penrose said.Tina’s mother was 17 years old and was still a child in care when Tina was born on New Year’s Day in 1999. Both her parents struggled with addictions.Five years later, her father asked Tina’s great-aunt Thelma Favel to take care of her and her sibling on the reserve northwest of Winnipeg. It was a relatively stable time in the young girl’s life.That changed when Tina’s father was murdered in 2011. Tina’s caregiver tried to get help for the young girl from victim services. But because of questions about who was the teen’s legal guardian, she never received counselling.In June 2014, Tina left to try to reconnect with her mother in Winnipeg. When Favel didn’t hear from the girl, she called Child and Family Services for help.The report outlines how Tina’s high-risk behaviour rapidly escalated in her final two months. She disappeared, was homeless, developed addictions and was sexually exploited.But she also reached out several times for help.On one occasion Tina called Child and Family Services but no one arranged to pick her up. Workers told the teen to ride her bicycle to a shelter.There’s no evidence she arrived.The report says Tina disclosed to her child-welfare agency that she was hanging out with a 62-year-old, meth-using man. Court heard during the second-degree murder trial of Raymond Cormier–who was acquitted last year in Tina’s death–how the young girl was associating with the older man and he admitted he was sexually attracted to her.Social workers believed Tina had been sexually assaulted, but the agency still dropped the teenager off with a contracted care worker at a downtown hotel. Tina walked away from the hotel shortly after.Just days later her 72-pound body, wrapped in a duvet cover and weighed down by rocks, was pulled from the Red River.Recommendations from the Child and Youth AdvocatePenrose makes five recommendations which she says need to be acted on quickly because children and youth are still facing the same risks and getting the same responses as Tina.The first is for Manitoba Education and Training to reevaluate the use of suspensions and expulsions in public schools. Penrose pointed to the recently-formed Commission on Kindergarten to Grade 12 Education which carefully examines the uses of those punishments so they can be limited, reduced, and phased out.READ MORE: ‘Don’t talk to each other’: Inside Manitoba’s child protection hearingsThe second recommendation is for Manitoba Health, Seniors, and Active Living which, ten months after the province handed down a mental health and addiction strategy, has yet to reveal implementation plans.Penrose has also recommended for Manitoba Justice – Victim Services to “address the quality control measures that were lacking” in their interactions with Tina and her family. “While this system was involved for a number of years, barriers to access the service were plenty and overall, the service was not delivered to Tina in child-centred ways.”The next is aimed at Child and Family Services and its responsibility to kids in need of protection.READ MORE: ‘Traumatic to witness a lack of empathy’ says mother of apprehended newborn“What Tina might have benefited from was access to the full continuum of services for children at imminent danger, and this continuum includes safe and secure treatment facilities that are therapeutic, culturally-informed, and effective – or, as Tina described to her CFS agency, a place where it feels like home,” Penrose’s report continues.And lastly, Penrose points at Manitoba Families to create a new protocol with individually-tailored response plans for missing kids. “Access to time-sensitive safety and care information about children who are missing might mean the difference between life and death for some youth.”The report says response plans specific to each case are imperative because of a strong correlation between missing persons, sexual exploitation, and “other harms that can place young people at immediate risk of injury and death.”The highly anticipated report was released on Tina’s home reserve.Not much has changed since Tina’s 2014 death: PenroseOver the course of the investigation, Penrose said one thing had been made abundantly clear–that not enough has changed since Tina’s tragic death five years ago.“In fact, what we know to be true from the youth we are working within our advocacy program and who are still alive today, and which has been confirmed by public systems throughout this process, is that children and youth who present with the same issues today may find themselves getting the same responses and experiencing the same barriers to service that Tina did.”Penrose urges the government agencies to heed her recommendations as change cannot be put off any longer, since for many at-risk teens struggle with structural barriers for many months and years and the “downward spiral gathers speed rapidly”.She said in her report that interventions and critical response measures often–and in the case of Tina–come too late because a threshold must be met before action is triggered.“Our track record in Manitoba is not good. We are home to the highest numbers of children in care, highest numbers of youth in custody, and highest numbers of missing children. These are the outcomes when services and investments are not intensively targeted on the early years and on the prevention of crisis.”Now, according to the advocate, Manitoba needs to jump to a more proactive approach.“The solutions lie upstream. If the focus of our resources and interventions keep our eyes locked on the results of trauma, then we will ignore the reasons that cause the trauma and our province will continue to see ballooning numbers of youth involved in child and family services, youth justice, and youth who are in need of emergency detox and treatment.“We can do better.”-with files from the Canadian Presslast_img read more

Star Trek on Mars NASA spots Starfleet logo in dune footprint

first_img“Enterprising viewers will make the discovery that these features look conspicuously like a famous logo,” the team quipped.The intriguing Mars formation has a long geologic history. It started as a crescent-shaped dune that became an island in a sea of lava, but the sand eventually blew away in the wind. “These are also called ‘dune casts’ and record the presence of dunes that were surrounded by lava,” planetary scientist Ross Beyer explained. A wider MRO view of the landscape shows more of the insignia-like impressions.marsdunefootprintEnlarge ImageThese “dune footprints” have some accidental Star Trek flair. NASA/JPL/University of Arizona Beyer made sure to point out the resemblance to the Star Trek logo is “only a coincidence.” There is no credible evidence of Star Trek fans having reached the surface of Mars. Yet. Share your voice 41 weird objects seen on Mars, explained Enlarge ImageThis Mars dune cast looks like it should be on Captain Kirk’s chest. NASA/JPL/University of Arizona NASA’s Mars Reconnaissance Orbiter looks down on the Red Planet and sees all sorts of fantastical formations that resemble everything from Beaker the Muppet to Pac-Man. A new MRO view will inspire you to whip out your Vulcan salute.The MRO HiRise camera team at the University of Arizona on Wednesday highlighted a Martian sand dune formation that could be a doppelganger for the classic swooping Starfleet logo. Tags Comments 43 Photos Caption Spotlight (12 Jun 2019): Dune Footprints in HellasEnterprising viewers will make the discovery that these features look conspicuously like a famous logo.More: https://t.co/CAq5xBbDwfNASA/JPL/University of Arizona#Mars #science pic.twitter.com/N5MfKQPiYt— HiRISE (NASA) (@HiRISE) June 12, 2019 Sci-Tech 8 NASA Space Star Treklast_img read more

Stranger author Omair Tarique says passion is contagious

first_imgOmair TariquePR HandoutThe age of Internet dawned on us with the promise of liberation, connecting millions together and providing a platform for each. Artists all around the world found a place to showcase their work thus every hidden dairy found a safe space, and Omair Tarique was not hesitant to join this sudden salvation of a generation.The twenty-two-year-old writer, who hails from the city of Kolkata, is currently pursuing English Honours from Calcutta University, found the love for written word in his early teens. Not only did Tarique believe in the power of language and the various repercussions it can have on people, but for him writing is a doorway to another world, a break from reality. He made his publication debut on May 10 2017 with Stranger a collection of short stories. Right now, he is working on his next book.It was not a surprise when Tarique co-founded The Scribbled Stories with Mohit Kumar on July 2, 2015. Today, India’s largest storytelling platform has become a hideaway for most of the millennials, with the following of almost 2 million on Facebook and Instagram. In the writing community, having a FanPost with your name on The Scribbled Stories is akin to a pilgrimage completed.If Omair found a haven in writing, he found peace in reading. The young author is widely known for his fondness of books: from organizing monthly Readathons, having his own online book club to reviewing books and just encouraging people to start reading, this man is full of passion.Some people know him as a ‘Book Fairy’ — if he adores a book, he will leave a copy of the same in cafés for others to find. On most days, Tarique survives on coffee, good movies and music whilst drowning in work. However, now on weekends he hosts an AMA for his readers, largely trying to help teenagers in angst and every person who thinks they are alone.He manages a team of twenty-seven writers at The Scribbled Stories, who come from different countries and walks of life. Tarique also curates stories submitted at the organisation’s submission portal. With his team, he has conducted various workshops in colleges across the country — from IITs to Liberal Arts Colleges.They say if the people you work with respect you, you cannot ask for anything else, and Tarique’s team carries nothing but admiration for him. Ansab Amir, Curator at The Scribbled Stories considers Omair as his supportive mentor and a well-balanced team member while Harshpreet, the Community Manager said, “Omair is more empathetic than you would ever imagine, the kind where he has observed you enough to know what will make you feel better when you are not okay. I doubt I will find a better colleague.”During his TEDx Talk at KL University, Tarique said, “Passion is contagious. I am passionate about reading, about writing, about stories. If you are passionate about something, like music, go back home after this event, pick up your instrument and record yourself playing something. Upload it even if it is bad. The way I see it, you either improve with criticism or get more confident with support… Each of you sitting in this room is an idea. And ideas can change the world.”He encourages every person to unabashedly just be themselves, the only way one can live their truth. Despite having marked numerous milestones just at the age of twenty-two, Omair Tarique is extremely grounded and keeps striving for more. Perhaps the reason behind his accumulating pile of successes. His journey stands as epitome of inspiration to many every day saying you do not need to speak in order to leave a mark.last_img read more

Over 100 hurt in New York train derailment

first_imgInvestigators assess damage after a Long Island Railroad train derailed at Atlantic Terminal in Brooklyn, New York City, US. Photo: ReutersA New York City train derailed at a downtown Brooklyn terminal during Wednesday’s morning rush hour, injuring more than 100 commuters in the metropolitan area’s second major rail accident since late September.Emergency crews swarmed Atlantic Terminal after the Long Island Rail Road train went off the tracks inside the busy transportation hub at 8:20 am local time (1320 GMT), the New York City Fire Department said.While none of the injuries were life-threatening, at least 11 people were sent to the hospital, Deputy Assistant Chief Dan Donoghue said at a briefing at the crash site.The train, arriving from the Queens neighborhood of Far Rockaway, failed to stop on time. Traveling at a fairly slow speed, it derailed after striking a bumping block, New York Governor Andrew Cuomo said at the briefing.A National Transportation Safety Board investigator told reporters that about 430 passengers and three crew members were on board the train at the time of the collision and that 104 people were injured.The front two cars of the six-carriage train were severely damaged. The station’s partitions and bumping block, which prevents railway vehicles from going past the end of a section of track, were also damaged.Passengers said the blood and chaos following the derailment were frightening.“There were people crying,” said Aaron Neufeld, a 26-year-old paralegal who commutes on the rail line daily. “I saw some bloody faces.”Neufeld, who was riding in the second car, said the train appeared to be approaching normally until it crashed, knocking passengers on top of one another and shattering glass windows.“Bags went flying,” he said. “People were thrown to the ground.”The engineer was probably responsible for failing to stop the train before it hit the bumper, said Tom Prendergast, chairman of the Metropolitan Transportation Authority, the agency that runs the railroad.The train was traveling between 10 and 15 miles per hour (16 to 24 km per hour) as it approached the bumper, he said, which is standard.“At that speed, it’s pretty much the locomotive engineer’s responsibility to stop the train,” Prendergast said as he stood beside Cuomo at the briefing. Investigators will interview the engineer, the conductor and brakeman to determine the cause of the accident, he said.There were no major service disruptions for other Long Island Rail Road lines at the terminal, an MTA official said.In late September, a New Jersey Transit train crashed into a terminal in Hoboken, New Jersey, killing one woman and injuring 114 people, including the engineer.Cuomo, who has made infrastructure improvements a centerpiece of his agenda, said Wednesday’s incident was minor in comparison. The most serious injury in the crash was a broken leg, he said.“There was extensive damage in Hoboken,” Cuomo said. “That train was coming in much faster, did much more damage.”The US Federal Railroad Administration and the National Transportation Safety Board said they were sending investigators to the scene.The Long Island Rail Road is the United State’s largest commuter rail system, serving more than 330,000 passengers a day, according to the American Public Transportation Association.Atlantic Terminal, which also connects commuters to nine city subway lines, is one of the busiest New York stations.last_img read more

UPDATE Family Of Houston Immigrant Says They Are Hurting After He Was

first_img Share Photo courtesy of the Andrés familyThese montage of photos show Carlos Andrés, who is originally from Guatemala, with his family.The family of a Guatemalan man recently arrested by Immigration Customs and Enforcement (ICE) agents in Houston said Friday they are hurting because he is the bread-winner, and contended they deem his detention unfair because, according to them, he doesn’t have a criminal record.The wife and children of Carlos Andres-Elias, 30, spoke at a press conference organized by the pro-immigration reform group Immigrant Families and Students in the Struggle (FIEL, by its Spanish acronym).According to César Espinosa, FIEL’s executive director, Andres-Elias works in the construction sector.Andres-Elias is married to Marcela Rivera, 31 years-old and originally from Mexico, with whom he has fathered five children. All of Andres-Elias children were born in the United States and one of them has a learning disability, according to Rivera.FIEL’s Espinosa, who cited Rivera and Jorge Cantú –Andres-Elias’ immigration lawyer– as his sources explained that Andres-Elias had been previously deported in December 2005, even though he had been granted a hearing with an immigration judge. He re-entered the U.S. without the proper immigration documents in February 2006 and the fact that he had not attended his immigration hearing in 2005 is what triggered an “order of removal,” Espinosa claims.Leticia Zamarripa, an ICE spokeswoman, confirmed in an email sent to Houston Public Media that Andres-Elias “illegally entered the country Dec. 10, 2005, and was deported on Dec. 30, 2005.”Zamarripa added that Andres-Elias illegally re-entered in the U.S. in 2006 and that constitutes a felony.Rivera, Andres-Elias’ wife, said ICE agents detained her husband  on January 19th this year at an apartment complex located in southwest Houston, where they live, as he was getting ready to leave for work.Rivera told Houston Public Media that her husband told her by phone –after he had been detained– that the ICE agents were not specifically looking for him, but for other people. However, according to the wife, after asking Andres-Elias and a co-worker some questions, the agents decided to detain them.ICE’s Zamarripa noted in her email that the apartment complex where Andres-Elias lives “was identified as part of a targeted enforcement operation.”No work permitAccording to Rivera, Andres-Elias showed the ICE agents a consular ID issued by Guatemala, his country of origin, but he then admitted he did not have a work permit.“It is unjust what they are doing to my husband, migration (authorities), because my husband is not a criminal, he is not a delinquent, he was simply going to work,” Rivera stressed at the press conference.Asked about what she plans to do in the immediate future, Rivera said that she is facing a “complicated” situation because her husband “was the one that worked, he was the one that covered the expenses at our household.”According to Rivera, Andres-Elias is currently at a detention facility for undocumented immigrants located in Conroe, about 40 miles north of Houston. He was denied a bail bond during a hearing that took place this week.last_img read more

Implementing Dependency Injection in Swift Tutorial

first_imgIn software development, it’s always recommended to split the system into loosely coupled modules that can work independently as much as they can. Dependency Injection (DI) is a pattern that helps to reach this goal, creating a maintainable and testable system. It is often confused with complex and over-configurable frameworks that permit us to add DI to our code; in reality, it is a simple pattern that can be added without too much effort. This article is taken from the book Hands-On Design Patterns with Swift by Florent Vilmart, Giordano Scalzo, and Sergio De Simone.  This book demonstrates how to apply design patterns and best practices in real-life situations, whether that’s for new or already existing Swift projects. You’ll begin with a quick refresher on Swift, the compiler, the standard library, and the foundation, followed by the Cocoa design patterns to follow up with the creational, structural, and behavioral patterns as defined by the GoF.  To follow along with the examples implemented in this article, you can download the code from the book’s GitHub repository. In this article, we’ll see what Dependency Injection is, where it comes, and how it’s defined so that we can then discuss various methods to implement it, having a clear understanding of its principles. Dependency Injection, a primer Dependency Injection is one of the most misunderstood concepts in computer programming. This is because the Dependency Injection borders are quite blurry and they could overlap with other object-oriented programming concepts. Let’s start with a formal definition given by Wikipedia: “In software engineering, Dependency Injection is a software design pattern that implements inversion of control for resolving dependencies.” To be honest, this is not really clear: what is Inversion of Control? Why is it useful for resolving dependencies? In procedural programming, each object interacts with all of its collaborators in a direct way and also instantiates them directly. In Inversion Of Control, this flow is managed by a third party, usually, a framework that calls the objects and receives notifications. An example of this is an implementation of a UI engine. In a UI Engine, there are two parts: the Views and the Models part. The Views part handles all the interaction with the users, such as tapping buttons and rendering labels, whereas the Models part is responsible for business logic. Usually, the application code goes in the Models part, and the connections with the Views are done via callbacks that are called by the engine when the user interacts with a button or a text field. The paradigm changes from an imperative style where the algorithm is a sequence of actions, like in do this then do that, to an event style, when the button is tapped then call the server. The control of the actions is thus inverted. Instead of being the model that does things, the model now receives calls. Inversion of Control is often called Hollywood Principle. The essence of this principle is, “Don’t call us, we’ll call you,” which is a response you might hear after auditioning for a role in Hollywood. In procedural programming, the flow of the program is determined by the modules that are statically connected together: ContactsView talks to ContactsCoreData and  ContactsProductionRemoteService, and each object instantiate its next collaborator. In Inversion of Control, ContactsView talks to a generic ContactsStore and a generic ContactsRemoteService whose concrete implementation could change depending on the context. If it is during the tests, an important role is played by the entity that manages how to create and connect all the objects together. After having defined the concept of IoC, let’s give a simpler definition of DI by James Shore: “Dependency Injection” is a 25-dollar term for a 5-cent concept. […] Dependency Injection means giving an object its instance variables. Really. That’s it.” The first principle of the book Design Patterns by the Gang of Four is “Program to an interface, not an implementation” which means that the objects need to know each other only by their interface and not by their implementation. After having defined how all the classes in software will collaborate with each other, this collaboration can be designed as a graph. The graph could be implemented connecting together the actual implementation of the classes, but following the first principle mentioned previously, we can do it using the interfaces of the same objects: the Dependency Injection is a way of building this graph passing the concrete classes to the objects. Four ways to use Dependency Injection Dependency Injection is used ubiquitously in Cocoa too, and in the following examples, we’ll see code snippets both from Cocoa and typical client-side code. Let’s take a look at the following four sections to learn how to use Dependency Injection. Constructor Injection The first way to do DI is to pass the collaborators in the constructor, where they are then saved in private properties. Let’s have as an example on e-commerce app, whose Basket is handled both locally and remotely. The BasketClient class orchestrates the logic, saves locally in BasketStore, and synchronizes remotely with BasketService: protocol BasketStore { func loadAllProduct() -> [Product] func add(product: Product) func delete(product: Product)}protocol BasketService {func fetchAllProduct(onSuccess: ([Product]) -> Void)func append(product: Product)func remove(product: Product)}struct Product {let id: Stringlet name: String//…} Then in the constructor of BasketClient, the concrete implementations of the protocols are passed: class BasketClient { private let service: BasketService private let store: BasketStore init(service: BasketService, store: BasketStore) { self.service = service self.store = store }func add(product: Product) {store.add(product: product)service.append(product: product)calculateAppliedDiscount()//…}// …private func calculateAppliedDiscount() {// …}} In Cocoa and Cocoa Touch, the Apple foundation libraries, there are a few examples of this pattern. A notable example is NSPersistentStore in CoreData: class NSPersistentStore: NSObject { init(persistentStoreCoordinator root: NSPersistentStoreCoordinator?, configurationName name: String?, URL url: NSURL, options: [NSObject: AnyObject]?)var persistentStoreCoordinator: NSPersistentStoreCoordinator? { get }} In the end, Dependency Injection as defined by James Shore is all here: define the collaborators with protocols and then pass them in the constructor. This is the best way to do DI. After the construction, the object is fully formed and it has a consistent state. Also, by just looking at the signature of init, the dependencies of this object are clear. Actually, the Constructor Injection is not only the most effective, but it’s also the easiest. The only problem is who has to create the object graph? The parent object? The AppDelegate? We’ll discuss that point in the Where to bind the dependencies section. Property Injection We have already agreed that Construction Injection is the best way to do DI, so why bother finding other methods? Well, it is not always possible to define the constructor the way we want. A notable example is doing DI with ViewControllers that are defined in storyboards. Given we have a BasketViewController that orchestrates the service and the store, we must pass them as properties: class BasketViewController: UIViewController { var service: BasketService? var store: BasketStore?// …} This pattern is less elegant than the previous one: The ViewController isn’t in the right state until all the properties are set Properties introduce mutability, and immutable classes are simpler and more efficient The properties must be defined as optional, leading to add question marks everywhere They are set by an external object, so they must be writeable and this could potentially permit something else to overwrite the value set at the beginning after a while There is no way to enforce the validity of the setup at compile-time However, something can be done: The properties can be set as implicitly unwrapped optional and then required in viewDidLoad. This is as a static check, but at least they are checked at the first sensible opportunity, which is when the view controller has been loaded. A function setter of all the properties prevents us from partially defining the collaborator list. The class BasketViewController must then be written as: class BasketViewController: UIViewController { private var service: BasketService! private var store: BasketStore!func set(service: BasketService, store: BasketStore) {self.service = serviceself.store = store}override func viewDidLoad() {super.viewDidLoad()precondition(service != nil, “BasketService required”)precondition(store != nil, “BasketStore required”)// …}} The Properties Injection permits us to have overridable properties with a default value. This can be useful in the case of testing. Let’s consider a dependency to a wrapper around the time: class CheckoutViewController: UIViewController { var time: Time = DefaultTime()}protocol Time {func now() -> Date}struct DefaultTime: Time {func now() -> Date {return Date()}} In the production code, we don’t need to do anything, while in the testing code we can now inject a particular date instead of always return the current time. This would permit us of testing how the software will behave in the future, or in the past. A dependency defined in the same module or framework is Local. When it comes from another module or framework, it’s Foreign. A Local dependency can be used as a default value, but a Foreign cannot, otherwise it would introduce a strong dependency between the modules. Method Injection This pattern just passes a collaborator in the method: class BasketClient {func add(product: Product, to store: BasketStore) {store.add(product: product)calculateAppliedDiscount()//…}// …private func calculateAppliedDiscount() {// …}} This is useful when the object has several collaborators, but most of them are just temporary and it isn’t worth having the relationship set up for the whole life cycle of the object. Ambient Context The final pattern, Ambient Context, is similar to the Singleton. We still have a single instance as a static variable, but the class has multiple subclasses with different behaviors, and each static variable is writeable with a static function: class Analytics { static private(set) var instance: Analytics = NoAnalytics() static func setAnaylics(analitics: Analytics) { self.instance = analitics } func track(event: Event) { fatalError(“Implement in a subclass”) }}class NoAnalytics: Analytics {override func track(event: Event) {}}class GoogleAnalytics: Analytics {override func track(event: Event) {//…}}class AdobeAnalytics: Analytics {override func track(event: Event) {//…}}struct Event {//…} This pattern should be used only for universal dependencies, representing some cross-cutting concerns, such as analytics, logging, and times and dates. This pattern has some advantages. The dependencies are always accessible and don’t need to change the API. It works well for cross-cutting concerns, but it doesn’t fit in other cases when the object isn’t unique. Also, it makes the dependency implicit and it represents a global mutable state that sometimes can lead to issues that are difficult to debug. DI anti-patterns When we try to implement a new technique, it is quite easy to lose control and implement it in the wrong way. Let’s see then the most common anti-patterns in Dependency Injection. Control Freak The first one is pretty easy to spot: we are not using the Injection at all. Instead of being Injected, the dependency is instantiated inside the object that depends on it: class FeaturedProductsController { private let restProductsService: ProductsServiceinit() {self.restProductsService = RestProductsService(configuration: Configuration.loadFromBundleId())}} In this example, ProductsService could have been injected in the constructor but it is instantiated there instead. Mark Seeman, in his book Dependency Injection in .NET, Chapter 5.1 – DI anti-patterns, calls it Control Freak because it describes a class that will not relinquish its dependencies. The Control Freak is the dominant DI anti-pattern and it happens every time a class directly instantiates its dependencies, instead of relying on the Inversion of Control for that. In the case of the example, even though the rest of the class is programmed against an interface, there is no way of changing the actual implementation of ProductsService and the type of concrete class that it is, it will always be RestProductsService. The only way to change it is to modify the code and compile it again, but with DI it should be possible to change the behavior at runtime. Sometimes, someone tries to fix the Control Freak anti-pattern using the factory pattern, but the reality is that the only way to fix it is to apply the Inversion of Control for the dependency and inject it in the constructor: class FeaturedProductsController { private let productsService: ProductsServiceinit(service: ProductsService) {self.productsService = service}} As already mentioned, Control Freak is the most common DI anti-pattern; pay particular attention so you don’t slip into its trap. Bastard Injection Constructor overloads are fairly common in Swift codebases, but these could lead to the Bastard Injection anti-pattern. A common scenario is when we have a constructor that lets us inject a Test Double, but it also has a default parameter in the constructor: class TodosService { let repository: TodosRepositoryinit(repository: TodosRepository = SqlLiteTodosRepository()) {self.repository = repository}} The biggest problem here is when the default implementation is a Foreign dependency, which is a class defined using another module; this creates a strong relationship between the two modules, making it impossible to reuse the class without including the dependent module too. The reason someone is tempted to write a default implementation it is pretty obvious since it is an easy way to instantiate the class just with TodoService() without the need of Composition Root or something similar. However, this nullifies the benefits of DI and it should be avoided removing the default implementation and injecting the dependency. Service Locator The final anti-pattern that we will explore is the most dangerous one: the Service Locator. It’s funny because this is often considered a good pattern and is widely used, even in the famous Spring framework. Originally, the Service Locator pattern was defined in Microsoft patterns & practices’ Enterprise Library, as Mark Seeman writes in his book Dependency Injection in .NET, Chapter 5.4 – Service Locator, but now he is advocating strongly against it. Service Locator is a common name for a service that we can query for different objects that were previously registered in it. As mentioned, it is a tricky one because it makes everything seem OK, but in fact, it nullifies all the advantage of the Dependency Injection: let locator = ServiceLocator.instancelocator.register( SqlLiteTodosRepository(),forType: TodosRepository.self)class TodosService {private let repository: TodosRepositoryinit() {let locator = ServiceLocator.instanceself.repository = locator.resolve(TodosRepository.self)}} Here we have a service locator as a singleton, to whom we register the classes we want to resolve. Instead of injecting the class into the constructor, we just query from the service. It looks like the Service Locator has all the advantages of Dependency Injection, it provides testability and extensibility since we can use different implementations without changing the client. It also enables parallel development and separated configuration from the usage. But it has some major disadvantages. With DI, the dependencies are explicit; it’s enough to look at the signature of the constructor or the exposed properties to understand what the dependencies for a class are. With a Service Locator, these dependencies are implicit, and the only way to find them is to inspect the implementation, which breaks the encapsulation. Also, all the classes are depending on the Service Locator and this makes the code tightly coupled with it. If we want to reuse a class, other then that class, we also need to add the Service Locator in our project, which could be in a different module and then adding the whole module as dependency where we wanted just to use one class. Service Locator could also give us the impression that we are not using DI at all because all the dependencies are hidden inside the classes. In this article, we covered the different flavors of dependency injection and examines how each can solve a particular set of problems in real-world scenarios. If you found this post useful, do check out the book, Hands-On Design Patterns with Swift. From learning about the most sought-after design patterns to comprehensive coverage of architectural patterns and code testing, this book is all you need to write clean, reusable code in Swift. Read Next Implementing Dependency Injection in Google Guice [Tutorial] Implementing Dependency Injection in Spring [Tutorial] Dagger 2.17, a dependency injection framework for Java and Android, is now out!last_img read more